Forum Moderators: open
<script type="text/javascript">
function foo(){alert("foo");}
function foo(){alert("bar");}
</script>
<input type="button" onclick="foo();">
Whichever one is defined in this case is going to be the one to get called because you're assigning the function to foo, and then overwriting it with a new function.
Can you post some code? It's difficult to debug without seeing the code.
The ideal situation would be to have one script fire and then 3 or 4 seconds later the other one fires.
Any thoughts?
-s-
<!--
//LEGAL NOTICE
//This code is copyrighted by Ken Clark 2005
//Use of this code in any form without authorization will result in a legal encroachment of the copyright
//DO NOT CONSIDER USING THIS SCRIPT OR ANY PART OF IT WITHOUT THE PROPER LICENSE
// contact info snipped
popNotOpenedYet = true;
document.onclick = function() {
if (document.cookie.indexOf("popopened=")!= -1) { popNotOpenedYet = false; }
if(popNotOpenedYet) {
popwinOBJ = window.open('http://www.mysite.com/index.html', 'nameMe', 'top=5,left=35,toolbar=0,menubar=0,scrollbars=1,status=0,resizable=1,width=600,height=555');
popwinOBJ.focus();
popNotOpenedYet = false;
document.cookie = "popopened=1";
}
}
//-->
[pageresource.com...]
Keeping in mind this timeout will also prevent the rest of your page from loading, absolutely nothing will happen during this pause that I know of.
We are trying to execute two copies of this script to open 2 different navigation windows at the same time.
Is this script within a function? I'm assuming also that this script is inline in your document, and not stored in a separate .js file (I make that assumption because I see HTML comments). I don't see anything being called twice, nor do I see this inside a function. It looks like you're assigning a function to the body onclick event handler.
Have you tried eliminating the cookie part and just checking the boolean value?
popNotOpenedYet = true;
document.onclick = function()
{
if(popNotOpenedYet)
{
popwinOBJ = window.open('http://www.mysite.com/index.html', 'nameMe', 'top=5,left=35,toolbar=0,menubar=0,scrollbars=1,status=0,resizable=1,width=600,height=555');
popNotOpenedYet = false;
popwinOBJ.focus();
}
}
Note, I don't see how you're trying to open 2 copies of a document though. ?
The above script is used twice - all the test are inline, if we get it to work it will be used as one or two js files.AS it stands now, it skips the first inline script and executes the second one...
I think you are confused. Nothing will just execute in the script you pasted. It requires the user to click the document. If you do this twice:
document.onclick = function() {
All you are doing is overwriting the onclick event. It will NOT execute this function twice.
<script language="JavaScript" type="text/javascript" defer="defer">
<!--
popNotOpenedYet = true;
document.onclick = function() {
if(popNotOpenedYet) {
popwinOBJ = window.open('http://www.mysite.com/test1.html', 'nameMe2', 'top=5,left=35,toolbar=0,menubar=0,scrollbars=1,status=0,resizable=1,width=600,height=555');
popwinOBJ.focus();
popNotOpenedYet = false;
popwinOBz = window.open('http://www.mysite.com/1stc/test2.html', 'nameMe', '');
popwinOBz.blur();
popNotOpenedYet = false;
}
}
//-->
</script>
<script type="text/javascript">
<!--
function openWindow1()
{
popwinOBJ = window.open('http://www.mysite.com/test1.html', 'nameMe2', 'top=5,left=35,toolbar=0,menubar=0,scrollbars=1,status=0,resizable=1,width=600,height=555');
popwinOBJ.focus();}
function openWindow2()
{
popwinOBz = window.open('http://www.mysite.com/1stc/test2.html', 'nameMe', '');
popwinOBz.blur();}
window.onload = function()
{
openWindow1();
self.setTimeout('openWindow2()', 4000);
}
//-->
</script>