473,761 Members | 9,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.writte n. 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 2824
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.create Element('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.writte n.


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.create Element('script ');
bar.src = 'mypath/myscript.js';

document.body.a ppendChild(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***@potatora dio.f2s.com> wrote in message
news:c4******** *************** ***@posting.goo gle.com...
"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.create Element('script ');
bar.src = 'mypath/myscript.js';

document.body.a ppendChild(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
2356
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 some calculations and write out a new document using document.write(). One of the lines it writes is (the whole script is at the bottom of this email). pageData = PageData+"<b>Patient Data</b><br>Wt: "+weight+" "+weightUnits+" &nbsp&nbsp Ht:...
2
2391
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 thumbnails, and works quite well execpt that on dial up it is unbearably slow. The Thumbnails themselves are only 10kb but the total of them is a lot larger. and it appears to need to load them all before it will display any.
3
3771
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 detect the browser and then based on the success of loading the plugin either show the Flash movie (swf file) or show a jpeg. Any help is appreciated as I have adjusted the syntax of having nested script tags within each other without any success. ...
3
3280
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 solve the problem. You can find the article at http://www.codeproject.com/java/javaappletwaitmsg.asp I have adapted the code to my situation but can't get it to work. Maybe someone has an idea how to fix it... Here is the code Cheers, Jacques...
1
2604
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 page). The DEFER method won't work because the document.write just starts a new page. I was hoping to leave a DIV where the result should end up. Then at the end of the page create a child of this DIV or another DIV that lays on top of this...
5
5210
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 to wait for the external resource to load to show up the page, thus giving a perceiving faster load time for the user.
6
8315
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. removeChild: http://www.jsonline.com/preview/richmedia6.asp The innerHTML rewrite acts the same way. If you click "close ad" in the upper right corner before the page has loaded completely then the page will stop loading and elements could be missing.
2
2842
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 encountering a very mysterious bug that I can't seem to get rid of. When loading the page in Internet Explorer, everything works, and in Firefox it works except for one problem: the page never stops loading. The script runs and everything parses but it...
6
2775
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: 1. document.write("<script src= language='JavaScript'></script>); 2. sc = document.createElement("<script>"); sc.setAttribute("src", ); and append this to the head
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9923
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.