washingtonirvine Posted June 4, 2010 Share Posted June 4, 2010 Im trying to learn more on popup writting in js, i want more than one popup to open on when a page is launched. im just fooling around with notepad pratice sites at the moment and working with this codeSCRIPT LANGUAGE="JavaScript">function popUp(URL) {day = new Date();id = day.getTime();eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=300,height=300,left = 533,top = 234');");}</script><BODY onLoad="java script:popUp('http://www.google.com')">how do i adjust this code to add another popup when page is loaded? Link to comment Share on other sites More sharing options...
End User Posted June 4, 2010 Share Posted June 4, 2010 how do i adjust this code to add another popup when page is loaded?Add another function that calls the popUP() function with a list of URLs. Change this: <BODY onLoad="java script:popUp('http://www.google.com')"> To something like this: <BODY onLoad="java script:popLaunch()"> The popLaunch() function would contain a list of URLs which would call the popUp() function: function popLaunch(){popUp('http://www.google.com')"popUp('http://www.w3schools.com')"} Link to comment Share on other sites More sharing options...
ShadowMage Posted June 4, 2010 Share Posted June 4, 2010 FWIW, I would ditch the eval() and set up your page variable as an array: function popUp(URL) { day = new Date(); id = day.getTime(); page = new Array(); var tmpWin = window.open(URL, id, 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=300,height=300,left = 533,top = 234'); page.push(tmpWin);} Other than that, End User hit the nail on the head in regards to creating several popups. Link to comment Share on other sites More sharing options...
washingtonirvine Posted June 4, 2010 Author Share Posted June 4, 2010 <HEAD><script LANGUAGE="JavaScript">function popLaunch(){popUp('http://www.google.com')"popUp('http://www.w3schools.com')"}<BODY onLoad="java script:popLaunch()">so whats missing to make this actually work Link to comment Share on other sites More sharing options...
ShadowMage Posted June 4, 2010 Share Posted June 4, 2010 Is that everything in your <script> tags? You still need to have the function you made. The body should be outside the <script> and the <head>. You also have an error (typo?) when you call the popUp function. You need to end the line with a ';' not ".popUp('http://www.google.com');popUp('http://www.w3schools.com');FWIW, you shouldn't really use the language attribute anymore. Use the type attribute instead:<script type='text/javascript'> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.