473,320 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Conditional loading of a remote script using document.write ... or?

I need to be able to conditionally load a remote script, using
the "<script src=..." syntax. Or some other way. I've seen
people writing about using the document.write method, but it's
not working like I want it to.

What's happening is, if I do a document.write(scriptcall), the
script loads, although sometimes very slowly... (?). Any inline
code is executed (I used an alert to verify that the script is
loading). But all the previous content of the page goes 'poof'.

If I look at the source of the page in this state, all I see
is the script tag I've document.written. I've tried using
document.close after writing the tag, and not using it, but
the results are the same. A blank page.

Wish there was a "loadscript(src)" function I could use.

Anybody know how to do what I want to do?
Jul 23 '05 #1
4 2793
Ivo
"Razzbar" wrote
I need to be able to conditionally load a remote script, using
the "<script src=..." syntax. Or some other way.
That syntax would not be reliable in a contional way. Try this:

if ( foo ) {
var bar = document.createElement('script');
bar.src = 'mypath/myscript.js';
}
I've seen people writing about using the document.write
method, but it's not working like I want it to.
If I look at the source of the page in this state, all I see
is the script tag I've document.written.


document.write() should only be used during the initial load of the page, if
at all. Upon loading, the document is closed and writing to it would result
in a new document being generated. This is what you see in the source.
HTH
Ivo
Jul 23 '05 #2
"Ivo" <no@thank.you> wrote in message news:<40***********************@news.wanadoo.nl>.. .
"Razzbar" wrote
I need to be able to conditionally load a remote script, using
the "<script src=..." syntax. Or some other way.
That syntax would not be reliable in a contional way. Try this:

if ( foo ) {
var bar = document.createElement('script');
bar.src = 'mypath/myscript.js';

document.body.appendChild(bar); }
Thank you! It didn't work, but I added the appendChild line,
and it's all hunky-dory.
I've seen people writing about using the document.write
document.write() should only be used during the initial load of the page, if
Besides, I think it's just a hokey kludgey way to do things. IMHO.
at all. Upon loading, the document is closed and writing to it would result
in a new document being generated. This is what you see in the source.
Exactly. It takes forever, then you see a blank page. Worst, you can't
reload the original page. Even with a pragma no-cache, if you reload
you get the .js file. You just can't get the original page back -- in
IE6. Probably browser specific. Too much of that going around.


HTH


You did. Thanks.
Jul 23 '05 #3
However, regarding loading of script by setting .src,
see the comments regarding Mozilla / Netscape at
http://groups.google.com/groups?thre...eda.datanet.hu

Csaba Gabor

"Razzbar" <gl***@potatoradio.f2s.com> wrote in message
news:c4**************************@posting.google.c om...
"Ivo" <no@thank.you> wrote in message news:<40***********************@news.wanadoo.nl>.. .
"Razzbar" wrote
I need to be able to conditionally load a remote script, using
the "<script src=..." syntax. Or some other way.


That syntax would not be reliable in a contional way. Try this:

if ( foo ) {
var bar = document.createElement('script');
bar.src = 'mypath/myscript.js';

document.body.appendChild(bar);
}


Thank you! It didn't work, but I added the appendChild line,
and it's all hunky-dory.
I've seen people writing about using the document.write
document.write() should only be used during the initial load of the

page, if
Besides, I think it's just a hokey kludgey way to do things. IMHO.
at all. Upon loading, the document is closed and writing to it would

result in a new document being generated. This is what you see in the source.


Exactly. It takes forever, then you see a blank page. Worst, you can't
reload the original page. Even with a pragma no-cache, if you reload
you get the .js file. You just can't get the original page back -- in
IE6. Probably browser specific. Too much of that going around.


HTH


You did. Thanks.

Jul 23 '05 #4
Ivo
"Csaba Gabor" pointed out:
However, regarding loading of script by setting .src,
see the comments regarding Mozilla / Netscape at
http://groups.google.com/groups?thre...eda.datanet.hu


The discussion in that thread is about a changing the source of an already
existing script while this one was about setting the source of a newly
created script. Even those browsers see a difference in that.
Ivo
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andrew V. Romero | last post by:
I have a script that I am working on for an intranet tool and in this script I have a form, which when submitted the onSubmit command calls calculate(). In this calculate function, I have it do...
2
by: Mekon | last post by:
I have never written a line of script in my life but I need some help with it now. I have this auto generated code which I want to modify if possible The script generates a strip of...
3
by: MN | last post by:
Hello all - I was hoping I could appeal to the gurus out there as I've researched this issue and can't seem to get this Flash movie to load at all. Below is my javascript code that I use to...
3
by: Jacques Chaurette | last post by:
Hello all , thanks in advance for any help. While looking for a solution to how to replace the grey box while an applet loads, a search of Google got me an article by Glenn s. Peffers that claims to...
1
by: ebrandmark | last post by:
I am trying to load a SCRIPT SRC tag that will result in a document.write into a specific location in my web page but not call for the SCRIPT SRC until the end of the page (so as not to delay the...
5
by: joaopedrogoncalves | last post by:
Hi, I want to load an external javascript file, get its results and stick them inside a <div> block. I also want to do this in several places on a web page. This way the browser doesn't have...
6
by: snazzy | last post by:
I have a problem where using innerHTML to rewrite a DIV or removeChild to kill a DIV that either of them, if excuted before the page is done loading will stop the page in its tracks. ...
2
by: nick.taylor | last post by:
Hi, I've been trying for weeks to figure out this problem. I'm developing a simple Javascript app that loads an XML file from a server, parses the contents, and displays them. But I am...
6
by: Venkatesh | last post by:
Hello All, I have couple of doubts regarding the concept of on-demand javascript loading using javascript code. I could see on the net different techniques for achieving this - techniques like:...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.