Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE/FF, Firefox doesn't execute and IE does. 1

Status
Not open for further replies.

MarkZK

Technical User
Jul 13, 2006
202
GB
Hi all,

I've tested the following script on both IE and Firefox and strangely enough IE does what I wanted to happen but Firefox doesn't.

I prefer to use Firefox so I was wondering if someone could explain this small sample code.

the page code:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
    <head>
        <title>Test</title>
    </head>
    <body>
<script type="text/javascript">
var i=1;var x;
setTimeout("upd()", 3000);

function upd(){
x=document.getElementById('pd1');
x.src="/"+i+".js";
}
</script>
<script type="text/javascript" id="pd1" src="/0.js"></script>
    </body>
</html>

the 0.js code:

Code:
alert('file 0');

the 1.js code:

Code:
alert('file 1');

and so on...

when testing it in IE it changes the src path of pd1 and alerts "file 1" as I wanted it to.

although testing it in Firefox it does change the src path (as I viewed formatted source) but doesn't execute the alert.

any ideas ?, also which browser is doing the right thing ?,
Thanks for the time.
 
MarkZK, FF will change the src but it will not attached the file. Instead of changing, why dont you create...

Code:
var i=1;var x;
setTimeout("upd()", 3000);


function upd(){
var x = document.createElement('script')
x.type = 'text/javascript' ;
x.src = '1.js' ;

document.getElementsByTagName('head')[0].appendChild(x);
}

This is untested but should work...

Good luck!

Nick
 
Thanks for the info and code Nickdel, it does work as I wanted it to now, on a side note, one thing that I'd predict having problems with in the future is, I plan to have it update 15-20 times eventually, so I'd imagine that would give me 20 script tags (in formatted code).

could I overwrite the one tag in some way, or delete the one before the newest on ?.

Thanks again.
 
Hi j4606, do you mean manually ?, I need it to update dynamically.

this is the code I'm going to use when the time comes.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
    <head>
        <title>Test</title>
    </head>
    <body>
<script type="text/javascript">
var i=1;
var load = document.createElement('script');
load.type = 'text/javascript' ;
load.src = '0.js';
load.id='pd1';
document.getElementsByTagName('head')[0].appendChild(load);
upd();

function upd(){
var n = document.getElementById("pd1");
n.parentNode.removeChild(n);
var x = document.createElement('script')
x.type = 'text/javascript' ;
x.src = i+'.js' ;
x.id='pd1';
++i
document.getElementsByTagName('head')[0].appendChild(x);
setTimeout("upd()", 3000);
}
</script>
    </body>
</html>

seems to do the job, thanks again for all posts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top