JavaScript - Pages Open In New Window Not Iframe
Hi all. First post so please be gentle.
My sites has a menu on the home page linking to a dozen other pages. My intention is to open those items into a main iframe also on the home page. I have put the <base target="iframe" > in the <Head> area and all seems to work in Opera but Internet Explorer and Firefox will both open new windows instead of loading into the iframe. Having said that. Links from WITHIN the iframe will open correctly in all browsers. Ideas in newbie-speak very much appreciated Regards, Phil Similar TutorialsI have a PARENT HTML page. Within it, there is an iFrame. Let us call page inside of iFrame is CHILD. I would like to following things: 1. When click button in CHILD, A NEW full size page opens and mouse focus moves to NEW. I used following scripts: function openFullWin(urlPara) { var windowFeatures = 'menubar=1,modal=0,resizable=1,scrollbars=1,status=1,toolbar=1,width=' + screen.availWidth + ',height=' + screen.availHeight + ',left=0,top=0'; var winNew = window.open(urlPara, '', windowFeatures); winNew.focus(); this.blur(); } In Firefox, if only PARENT widow there. It works property. However, if there is another window there, the focus moved to that window rather than the NEW. In IE, if there is another window there, the NEW open as a tab in that window, rather than as tab in PARENT. 2. When click button in CHILD, A NEW full size page opens and mouse focus moves to NEW. At meantime, the CHILD changes to a NEWCHILD page, but not on focus. I am never being able to do this. Please help. 3. When click button in CHILD, A NEW full size page opens to replace PARENT. Of course, the CHILD disappeared too. I am never being able to do this. Please help. window.open() doesn't open an entirely new window in FF3.6, just a new tab suggestions? Edit: Yeah, ok, so if i specify a size smaller than the current standard window, it'll be forced to open a new window. but what if i want a new standard sized window to open entirely? and in any case, i wan t amore direct solution where possible, thanks. Hi Ive found out how to force another browser window to open at a certain size when a link is clicked. Here's the whole line of code including the layer, the javascript and the image, <div id="Layer6" style="position:absolute; width:10px; height:8px; z-index:6; left: 561px; top: 310px"><a href="javascript:;" onClick="MM_openBrWindow('navigation%20instructions.htm','','width=50,height=50')"><img src="images/info.gif" width="15" height="15" border="0"></a></div> How do I adapt this so I can also specify the x&y co-ordinates of the opened window relative to the window that launched it. thanks alot Masten I am using a window.open to trigger a mailto: command. I don't want the window to stay open so I try to close it right after. The default email client launches correctly, but the window stays open and I get the following Javascript error: Unable to get value of the property 'close': object is null or undefined Code: Code: var win = window.open(mailto_link,'emailWindow'); win.close(); I do write some php, but have not much idea about JavaScript. I use window.open to open 10 pages simultaneously. I prefer to open them with a time delay from each other to put less load on the target server. This is my code with no delay. (I played around with setTimeout but can't get it to work.) PHP Code: <a href='http://www.".$new[9]."' onclick="window.open('http://www.".$new[0]."/'); window.open('http://www.".$new[1]."/'); window.open('http://www.".$new[2]."/'); window.open('http://www.".$new[3]."/'); window.open('http://www.".$new[4]."/'); window.open('http://www.".$new[5]."/'); window.open('http://www.".$new[6]."/'); window.open('http://www.".$new[7]."/'); window.open('http://www.".$new[8]."/')\" target='new300/'>Open 10</a> +++++++++++++++++++++++++++first window+++++++++++++++++++++++++ <html> <head> <script language="javascript"> var myWindow; function christDoes(){ mydWindow=open("second.html", "yes"); } </script> </head> <body><form name="myform" method=POST ACTION="sake.html" ><CENTER> <B>ENTER YOUR SUBJECT</B><INPUT TYPE="TEXT" NAME="subject"> <input type="button" name="ok" value="OK" onClick="christDoes()"> </form> </body> </html> +++++++++++++++++++++++++++parent window+++++++++++++++++++++++++ ++++++++++++++++++++++++++++child window++++++++++++++++++++++ <html> <head> <script language="javascript"> function me(){ displayColor(); } function displayColor() { callWindow=window.open("third.html","fine"); } var m=0; var fSubject = self.opener.document.forms[0].subject.value; if(fSubject.length>0){ if(isNaN(fSubject)){fSubject="";} else{opener.alert("Please enter figure");} numSub=parseInt(fSubject); if(numSub==2){var strSub="ab";} self.document.write("<center>" +"ENTER SUBJECT HERE" +"</center><br>"); var mercy="<HTML><BODY>" mercy +="<FORM ACTION='save.html' METHOD='POST'>" mercy +="<CENTER>" sub=new Array(strSub.length); for(var i=0; i<sub.length; i++){ m++; mercy +=m +"<input type='text' name='sub[i].toLowerCase()'>" +"<BR>"; opener.alert("You have entered" +m +"subjects"); } } mercy +="</CENTER></FORM></BODY></HTML><BR></BR>"; self.document.write(mercy +"<BR>"); self.document.bgColor="pink"; self.document.write("<center>" +"<input type='button' name='submit' value='SUBMIT'>" +"<center>"); } </script> </head> <body onload='me()'> </body> </html> ++++++++++++++++++++++++++++++child window++++++++++++++++++++ +++++++++++++++++++++++++++++++new window+++++++++++++++++++++ <html> <head> <script language="javascript"> function help(){ self.document.write("this is me") self.document.write("<center>" +"<input type='button' name='submit' value='SUBMIT'>" +"<center>"); } </script> </head> <body onLoad="help"> </body> </html> +++++++++++++++++++++++++++++++new window+++++++++++++++++++++ Can somebody help me with the code to make this button work? In the parent window when 2 is input in the textbox and 'OK' button clicked, the second window opens with 2 textbox and 'SUBMIT' button. If 'SUBMIT' button is clicked in the child window i want it to open the new window. Please help me out. Thanks. God bless in Jesus name. +++++++++++++++++++first window+++++++++++++++++++++++++ <html> <head> <script language="javascript"> var myWindow; function christDoes(){ mydWindow=open("second.html", "yes"); } </script> </head> <body><form name="myform" method=POST ACTION="sake.html" ><CENTER> <B>ENTER YOUR SUBJECT</B><INPUT TYPE="TEXT" NAME="subject"> <input type="button" name="ok" value="OK" onClick="christDoes()"> </form> </body> </html> +++++++++++++++++++first window+++++++++++++++++++++++++ +++++++++++++++++++second window++++++++++++++++++++++ <html> <head> <script language="javascript"> function me(){ displayColor(); } function displayColor() { callWindow=window.open("third.html","fine"); } var m=0; var fSubject = self.opener.document.forms[0].subject.value; if(fSubject.length>0){ if(isNaN(fSubject)){fSubject="";} else{opener.alert("Please enter figure");} numSub=parseInt(fSubject); if(numSub==2){var strSub="ab";} self.document.write("<center>" +"ENTER SUBJECT HERE" +"</center><br>"); var mercy="<HTML><BODY>" mercy +="<FORM ACTION='save.html' METHOD='POST'>" mercy +="<CENTER>" sub=new Array(strSub.length); for(var i=0; i<sub.length; i++){ m++; mercy +=m +"<input type='text' name='sub[i].toLowerCase()'>" +"<BR>"; opener.alert("You have entered" +m +"subjects"); } } mercy +="</CENTER></FORM></BODY></HTML><BR></BR>"; self.document.write(mercy +"<BR>"); self.document.bgColor="pink"; self.document.write("<center>" +"<input type='button' name='submit' value='SUBMIT' onClick='window.open('third.html', '')'>" +"<center>"); } </script> </head> <body onload='me()'> </body> </html> ++++++++++++++++++++++second window++++++++++++++++++++ ++++++++++++++++++++++third window+++++++++++++++++++++ <html> <head> <script language="javascript"> function help(){ self.document.write("this is me") self.document.write("<center>" +"<input type='button' name='submit' value='SUBMIT'>" +"<center>"); } </script> </head> <body onLoad="help"> </body> </html> ++++++++++++++++++++++third window+++++++++++++++++++++ Can somebody help me with the code to make this button work? In the parent window when 2 is input in the text box and 'OK' button clicked, the second window opens with 2 text box and 'SUBMIT' button. If 'SUBMIT' button is clicked in the child window i want it to open the third window. Please help me out. Thanks. God bless in Jesus name. *ADDED* Though i am advised to add 'window .open' as one of the arguments to the OK button which i did yet it doesn't work somebody please help me out! I am using Mozilla 3.6 could this mean that it doesn't support this? Hi, In my "main.js" file I need to create a new window with a button. If the button clicked a function in the "main.js" file is called. I tried the following, but new window does not see the function in the "main.js" file. function create_new_window() { my_window = window.open ("","mywindow1","status=1,width=350,height=150"); my_window.document.write('<H1>My Window ...</H1>'); my_window.document.write('<form><input type="button" value="Submit" onClick="submitData();"/></form>'); .... } function submitData() { ... } Hi All: I have a problem with a free script for an internal site search and I would like to tweek. I know nothing about javascript so be patient. What I want to do is to open a new window when you select a hyperlink in the results returned page. Here's the relevant code: Code: // ---------- script properties ---------- var include_num = 1; var bold = 0; // ---------- sites ---------- var s = new Array(); s[0] = "JSE^form.html^Enter JSE in the example above ...^open source, free, client side"; s[1] = "JSE DOCUMENTATION^doc.txt^JSE is a client-side local site search engine. Written entirely in JavaScript 1.3 it works with browsers from Netscape 4.7 to Microsoft Internet Explorer 6.0 ...^ faq, docs, instructions"; // ---------- end of script properties and sites ---------- var cookies = document.cookie; var p = cookies.indexOf("d="); if (p != -1) { var st = p + 2; var en = cookies.indexOf(";", st); if (en == -1) { en = cookies.length; } var d = cookies.substring(st, en); d = unescape(d); } var od = d; var m = 0; if (d.charAt(0) == '"' && d.charAt(d.length - 1) == '"') { m = 1; } var r = new Array(); var co = 0; if (m == 0) { var woin = new Array(); var w = d.split(" "); for (var a = 0; a < w.length; a++) { woin[a] = 0; if (w[a].charAt(0) == '-') { woin[a] = 1; } } for (var a = 0; a < w.length; a++) { w[a] = w[a].replace(/^\-|^\+/gi, ""); } a = 0; for (var c = 0; c < s.length; c++) { pa = 0; nh = 0; for (var i = 0; i < woin.length; i++) { if (woin[i] == 0) { nh++; var pat = new RegExp(w[i], "i"); var rn = s[c].search(pat); if (rn >= 0) { pa++; } else { pa = 0; } } if (woin[i] == 1) { var pat = new RegExp(w[i], "i"); var rn = s[c].search(pat); if (rn >= 0) { pa = 0; } } } if (pa == nh) { r[a] = s[c]; a++; } } co = a; } if (m == 1) { d = d.replace(/"/gi, ""); var a = 0; var pat = new RegExp(d, "i"); for (var c = 0; c < s.length; c++) { var rn = s[c].search(pat); if (rn >= 0) { r[a] = s[c]; a++; } } co = a; } function return_query() { document.jse_Form.d.value = od; } function num_jse() { document.write(co); } function out_jse() { if (co == 0) { document.write('Your search did not match any documents.<p>Make sure all keywords are spelt correctly.<br>Try different or more general keywords.'); return; } for (var a = 0; a < r.length; a++) { var os = r[a].split("^"); if (bold == 1 && m == 1) { var br = "<b>" + d + "</b>"; os[2] = os[2].replace(pat, br); } if (include_num == 1) { document.write(a + 1, '. <a href="', os[1], '">', os[0], '</a><br>', os[2], '<p>'); } else { document.write('<a href="', os[1], '">', os[0], '</a><br>', os[2], '<p>'); } } } You can see the search feature in action at http://qualityhealthplans.com It works great but I want to be able to select a particular page hyperlink and open it in a new window without leaving the search results page. Can anyone help? Hi Folks, here is the weirdest problem. I want open a url in the same window, replacing the current page. To test this I have created a simple script. The setup: I have two files in the same folder. abc.html and xyz.html. abc.html contains a button that calls this script: Code: function openWindow() { window.open( "xyz.html" ) ; } And this works fine, just as a test. But I want to open xyz.html in the same window, replacing abc.html . So I try: Code: window.open( "xyz.html" , "_self" ) ; does not work but simply reloads abc.html. I try: Code: window.location.href = "xyz.html"; does not work, but, again, simply reloads abc.html. What gives? The odd thing is, when it reloads the same page, abc.html, the address bar displays this at the end of the address: abc.html?button=Submit Any ideas on what may be going wrong here, or how I can get this to work? All this is being tested locally on my laptop - MacBook - and have tested in Safari and Firefox with the same results for both. Thanks in advance! Hello, I want to know how to open a new window when someone is closing a page. I mean for example, I have to two pages, if the user closes the first page when he clicks on Close button or close in his tab, a new window will open to open the second page. Thank you.
Code: <SCRIPT language=JavaScript> function DoSearch() { if (document.frmSearchID.txtIssueID.value != "") { if (isNaN(document.frmSearchID.txtIssueID.value)) { alert('Issue Numbers must be numeric');} else {document.location = "http://www.****.com/Apps/AddIssues/EditIssue.asp?IssueID=" + document.frmSearchID.txtIssueID.value + "&ProjectID=LRUSTARS";}}} </SCRIPT> <FORM style="display:inline" target="_blank" action="http://www.****.com/default.asp?ProjectID=LRUSTARS#" name="frmSearchID" onSubmit="javascript:DoSearch();return false;" method="post"> <INPUT class="formField1" name="txtIssueID"> <INPUT class="formBox" onClick="javascript:DoSearch(); return false;" type="submit" name="search" VALUE="Search"> </form> Cant seem to get it to open in a new window any help? Hi I'm new here and need some help; I spent so long with this and need either a miracle or a javascript expert! I have the code below which is used to open up a chat window, the problem is all browser treat this as a pop up and block it! What could be changed to get round this? $chat = "window.open( '" . SK_Navigation::href("private_chat", array("userKey"=>$pr_key, "oppUserKey"=>$opp_key, 'is_esd_session'=>1 )) . "', '', 'height=540,width=415,left=100,top=100,scrollbars=no,resizable=no' );"; Thanks dr Code: <a href=" javascript: myWindow = window.open('http://en59.tribalwars.net/game.php?village=3463&screen=premium&mode=transfer'); myWindow.document.forms[0].name.value='Gods Child';end" target="_blank">Donate Please</a> So, what I am trying to do is when you click the link, a new page opens to that site, then does document.forms[0].name.value='Gods Child'; I can get the page to open, but then it doesn't do the second part. If I run the second part in the url bar, when at the other site, it works how I want too, but not when I do it at the same time. NOTE: The only part that needs to be in this is document.forms[0].name.value='Gods Child'; and the link, but you can change the rest however you want. Hi all, I found this bookmarklet which I'm using in Firefox. Would anyone here be willing to modify it to display its results in a new tab, instead of using the current tab? Thanks in advance. Code: javascript:q=""+(window.getSelection?window.getSelection():document.getSelection? document.getSelection():document.selection.createRange().text);if(!q) q=prompt("Search terms [leave selection and box blank to list all pages] ...").replace(/\s\+/g,"%252B");if(q!=null)location="http://www.google.com /search?q="+q.replace(/\s+/g,"+")+"+site:"+location.hostname;void(0); when a user click on a link, it would open a new window in HTML it is something like this: Code: <a href="http://google.com" target="_blank">click here</a> How do I do this in Javascript? So a user would click on the link and it would open a new window. Here's my code Code: document.writeln('<tr><td>' + "http://google.com" + '</td></tr>'); I know window.open(url) would open a new window, but how do I make it clickable?? Any comments or suggestion would be greatly appreciated. thanks Hi I am attempting to integrate two dynamic applications. I have successfully created an iFrame in app A that serves the dynamic pages of app B. This enables me to preserve the site theme of app A. Most of app B's pages successfully display inside the app A iFrame. The problem is, when application B displays a page (inside app A's iFrame parent) clicking on a link inside that page opens that page in another iFrame (child) and I can't see what could be wrong... fresh pair of eyes would be good.... Code: <iframe id="listframe" name=target src="http://www.mysite.com/dynamicpages/" width="580" height="850" frameborder="0" scrolling="no" > </iframe> <script type="text/javascript"> window.onload = function () { var q = (document.location.search); document.getElementById('listframe').src += q; } </script> hi. i am looking for help (example) to open to a new window in the original window. the original window is blocked from any user inputs. a good example is here at http://www.dominos.com/home/index.jsp and click on "locations" button. is there a special name for this window.open? thanks I having trouble with this code, I have this timer running in a js file if the timer runs out then an alert box pops up letting the user know that they have been logged out. There is also a pop-up window and if the user press down on the key board then the timer resets. I have already done this in my test files, What I am trying to do is apply it to this other code and its a bit tricky. Below you will find my test code. test1.php PHP Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" language="javascript"> var test2 function popup() { test2=window.open( "test2.php", "myWindow", "status = 1, height = 300, width = 300, resizable = 0" ) } </script> </head> <body> <?php echo '<a href="#" onclick="popup()" >Click Here</a>'; echo '<embed src="logout_operator.wav" autostart="false" id="logout" width="0" height="1" loop="false">'; echo '<script type="text/javascript" language="javascript" src="test.js"></script>'; echo '<script type="text/javascript" language="javascript"> function timeout(logoutSound) { var soundLogout=document.getElementById(logoutSound); soundLogout.Play(); alert("Your session is expired please login again"); location = "http://www.google.com"; } </script>'; ?> </body> </html> test2.php (pop-up window) PHP Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" language="javascript" src="test.js"></script> </head> <body> <script type="text/javascript" language="javascript"> window.onkeydown = handle; function handle() { resetTimer(); return true; } </script> </body> </html> test.js Code: var timer = setTimeout("timeout('logout')", 5000); function resetTimer(d) { clearTimeout(timer); if (d!="done"){ if (location.href.indexOf("test2.php")!=-1){ window.opener.window.resetTimer("done"); } else{ test2.window.resetTimer("done"); } } timer = setTimeout("timeout('logout')", 5000); } What I am trying to do is apply the function and the button to this code: Code: var _h = { mi: function (link, title, ni, qi, width, height, ri) { return '<a href="' + link + '"' + (ri != null ? ' class="' + ri + '"' : '') + ' target="_blank" title="' + title + '" onclick="this.newWindow = window.open(\'' + link + '\', \'' + ni + '\', \'toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=' + width + ',height=' + height + ',resizable=1\');this.newWindow.focus();this.newWindow.opener=window;return false;">' + qi + '</a>'; } I have tried to put the test2 variable as _h but that didn't work at all. Any help would be much appreciated, thanks!!! Hello, I have an asp page to search for data. I like to open it in a new window while retain the search values. And I also can resize the window as well as set its attributes like height, width,etc. I created a js function like this: function posttopopup(formname, windowname) { if (! window.focus)return true; window.open('', windowname); formname.rel="nofollow" target=windowname; return true; } on my asp search page: <form method="post" action=search.asp" onSubmit="posttopopup(this, 'popupwindow')"> ..... <input type="button" name="Submit1" value="Search" onclick="if (isDate()) document.Search.submit();"> I keep getting errors like "document.search has no value..." What did I do wrong? Thanks. |