Welcome to WebmasterWorld Guest from 54.145.208.64

Forum Moderators: open

Message Too Old, No Replies

Run 2 similar scripts on the same page

Execute one script than another

   
11:07 pm on Dec 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have two similar scripts on a page and both do similar functions. The problems is, the last one in line is always the only one that works. Is there a way to tell the first script to execute and then have the second one run?

Thanks
-s-

9:19 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What triggers the execution of the scripts? I'm asking because it sounds like both get triggered by some window.onload event, which may be problematic.
9:31 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RonPK,

It's not an onload event but rather an onClick.

Any thoughts?

-s-

9:35 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Do these have the same function names? For example, are you doing something like this:

<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.

10:02 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The whole script is posted below. We are trying to execute two copies of this script to open 2 different navigation windows at the same time. So far only the last one opens with the first being ignored.

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";
}
}
//-->

10:17 pm on Dec 13, 2005 (gmt 0)



To run one, then pause, then run the next:

[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.

10:49 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month




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. ?

11:03 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fotiman,

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...

Thanks
-s-

11:35 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month




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.

12:15 am on Dec 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The goal is to get two windows out - I would be the first to admit I don't know the right terms to explain what I'm trying to do.

In a nut shell I want to get two windows out and in the best world, one window and a few seconds later the second one...

Any Thoughts?

-s-

12:23 am on Dec 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Another way to look at it - is there w way to get the second window here to open 3 or 4 seconds later?

<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>

3:19 pm on Dec 14, 2005 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Something like this should work:


<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>

 

Featured Threads

Hot Threads This Week

Hot Threads This Month