homepage Welcome to WebmasterWorld Guest from 54.205.189.156
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Run 2 similar scripts on the same page
Execute one script than another
stcrim




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

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-

 

RonPK




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

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.

stcrim




msg:1471447
 9:31 pm on Dec 13, 2005 (gmt 0)

RonPK,

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

Any thoughts?

-s-

Fotiman




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

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.

stcrim




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

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

topsites




msg:1471450
 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.

Fotiman




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


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

stcrim




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

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-

Fotiman




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


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.

stcrim




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

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-

stcrim




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

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>

Fotiman




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

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>


Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved