473,696 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delayed SCRIPT Loading

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 DIV and place the results in there.

I can't use the innerHTML property of the DIV as it seems that SCRIPT
tags within that innerHTML are not executed and the result may have
SCRIPT tags.

I also can't use an IFRAME (which is the easy solution) for various
reasons.

I have tried to create a child SCRIPT element of the DIV - but the
document.write still writes at the bottom of the screen.

I also (a lot of requirements, I know) need this to be generic (I won't
know ahead of time the x,y location) and want to use this on a lot of
web pages.

So I want something like this:

Content....

Placeholder for SCRIPT SRC

More content

Call for SCRIPT SRC but results go over (in) the Placeholder
End of Page code.

Thanks for any assistance.

Ed Brandmark

Jul 23 '05 #1
1 2600
eb********@aol. com wrote:
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.
Then don't use document.write. Use DOM methods to modify your
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 DIV and place the results in there.
Reference your location using document.getEle mentById or similar.
I can't use the innerHTML property of the DIV as it seems that SCRIPT
tags within that innerHTML are not executed and the result may have
SCRIPT tags.


If you insert a script into a page, it will run as if it was
there when the page was loaded. You can also insert a script
with functions, then call them later.

Here's a sample HTML page:

<html>
<head>
<title>play</title>
<script type="text/javascript">
function addScript(){
var h = document.getEle mentsByTagName( 'head')[0];
var s = document.create Element('script ');
s.type = 'text/javascript';
s.src = 'play.js'
h.appendChild(s );
}
</script>
</head>
<body>
<button onclick="addScr ipt();">Add script</button>
<button onclick="hiMum( );">Hi mum</button>
<br>
<span id="outSpan"></span>
</body>
</html>

Save the following as "play.js" in the same directory:

if (document.getEl ementById && document.create TextNode){
var tx0 = document.create TextNode('hi mum 0');
document.getEle mentById('outSp an').appendChil d(tx0);
}

function hiMum() {
if (document.getEl ementById && document.create TextNode){
var o = document.getEle mentById('outSp an');
o.appendChild(d ocument.createE lement('br'));
o.appendChild(d ocument.createT extNode('hi mum 1'));
}
}
Clicking in "Add script" adds the script to the page. When
loaded, it runs and writes "Hi mum 0" to the page. Clicking on
"Hi mum" will added "Hi mum 1" to the page. Clicking on "Hi mum"
before then does nothing (or generates an error).
--
Rob
Jul 23 '05 #2

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

Similar topics

13
2331
by: Brian | last post by:
Hi all... This question is more for the GURUs out there. It is not a question on how to do something, but why it happens, and I am trying to figure out if there is a pattern. I am using IE, but this pattern also happens in Mozilla, but not always the same way... I am not as interested in how the browsers are different, but the big question is: Is there a pattern to what type of actions are delayed for after the scripts have finished, and...
3
1965
by: stan k. | last post by:
First of all let me clarify - I am not talking about having a bunch of images loaded all at once (or preloaded) and then controlling the display of the images after that point -- I know that can be done. I am talking about controlling the loading of those images themselves. I was told that the only way to do this was to dynamically write the html code via javascript and put time delays inbetween the dynamic creation of that html such as:
6
3120
by: Curious George | last post by:
I have a page that takes about 10 seconds to load the first time it is run. I would like to first display a little animated gif telling the user that the page is loading. How do I do this with .NET? I used to create a loading layer at the top of the page. Flush the layer to the buffer.
2
1889
by: hbchai | last post by:
I'm adapting the ajax-like asynchronous request pattern mentioned in this article: http://www.xml.com/pub/a/2005/11/09/fixing-ajax-xmlhttprequest-considered-harmful.html?page=2 for my Sudoku implementation: http://ttwhy.org/code/mosudoku.html By changing the "src" attribute of a script tag, I can dynamically load
4
2155
by: petermichaux | last post by:
Hi, I'm hoping for a reason I'm wrong or an alternate solution... I'd like to be able to dynamically include some javascript files. This is like scriptaculous.js library but their solution is broken in Firefox 1.5.0.1 on OS X. What happens with the Scriptaculous library is this In the html document the author only has to include one line
2
3209
by: boczek | last post by:
Hello all. I'm writing a small async webapp. in JavaScript and I'm using <script> element technique to load data. I'm usign <scriptbecause of cross domain restrictions with XmlRequest. The problem is when I remove a element that is currently loading from DOM (with removeChild) Firefox still loads it and waits with other scripts.
2
1849
by: wzhao2000 | last post by:
Back in COM time, it's possible to use #import statement in cpp to load COM object type info and use it at coding time. When the application is started, the underlying COM DLL will not be loaded until that part of code is called. Is there a similar thing in .Net (C#) application ? When I create C# application, I need to add reference to another assembly if I want to use its classes (I don't want to use reflection here). But this will...
4
6188
by: Quill_Patricia | last post by:
I have a Python script which is used to load data into a database. Up to now this script has been run by customers from the Windows command prompt using "python edg_loader.pyc". Any error messages generated are written to a log file. A project team working in the same company as me here would like to use this loading utility. They write UI applications for Windows using Java. They were able to launch the Python script from within Java by...
0
8667
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8597
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
9012
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8853
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6515
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
5857
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
4357
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...
0
4611
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1992
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.