473,226 Members | 1,655 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,226 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 2788
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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.