473,837 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

innerHTML & removeChild Problems - Page Stops Loading

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.

What am I missing here. I probably could load the ad at the very end of
the page, but that isn't an option right now. Looking for any
thoughts...

Thanks much,
Dennis

Nov 23 '05 #1
6 8322
VK
The provided link source is too big to even open it in Notepad. Do we
suppose to spend the whole week-end by studing your code? ;-)

Please provide the minimum code to illustrate your problem (and nothing
else).

An abstract suggestion: as a common rule you cannot
remove/replace/paint etc. something that doesn't exist yet. And an
element node doesn't exists until document DOM model is ready, and DOM
model is not ready until "onload".

Nov 23 '05 #2
sn****@gmail.co m wrote:
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.

What am I missing here. I probably could load the ad at the very end of
the page, but that isn't an option right now. Looking for any
thoughts...

Thanks much,
Dennis


What VK said. First step is to validate your document, the W3C validator
barfs and can't do it:

" Sorry, I am unable to validate this document because on line
1032-1033, 1038-1039, 1167, 1968 it contained one or more bytes
that I cannot interpret as utf-8 (in other words, the bytes found
are not valid values in the specified Character Encoding). Please
check both the content of the file and the character encoding
indication."
Don't use innerHTML, use DOM. Wait for the page to fully load before
messing with its innards.
--
Rob
Nov 23 '05 #3
Well there is no real way this is going to be validated, nor did I
expect anyone to sort through all the code. So I appreciate those who
responded.

I wanted to show the full working example. Just to visualize what I am
doing.

Right now a Flash ad is drawn in and call this function:

function mjsCFlash(){
var hasReqestedVers ion = DetectFlashVer( requiredMajorVe rsion,
requiredMinorVe rsion, requiredRevisio n);
myReference = getRefToDiv("mj sSWFf");
if((hasReqested Version==true) && (mjsRequire()== true)){
myReference.inn erHTML = '<a
href=\"http://oascentral.onwi sconsin.com/RealMedia/ads/click_lx.ads/%%PAGE%%/%%RAND%%/%%POS%%/%%CAMP%%/%%IMAGE%%/%%USER%%?\"><im g
src=\"http://www.jsonline.co m/ads/dmc/2005/tb-dmc-growingSM.gif\"
border=\"0\" alt=\"%%ALT%%\" ></a>';
}
changeSize(330, 80);
}

All the function calls work beautifully - the only issue is that if
this is called before the page is completely drawn then the page stops
loading. My question - is it possible to still do something similar and
get the result I need without having the page stop loading?

I only want to modify the contents of one DIV - and I don't want to
deal with a timer or ONLOAD to close the ad because the user needs to
have that ability immediately. If I did this with an IFRAME would that
make more sense? There are other ad technologies out there
closing/collapsing/rewriting DIVs - just working on my solution and
trying to find a way around this bug.

Thanks much for the replies...

Nov 23 '05 #4
VK
You definitely *can* do it.

*But* if you want to insert a block of content before page finished
loading, you have to forget about the DOM: it is applicable only to a
finished document structure. You have to use write() method instead:

<!-- your page -->
....
<div id="myFlash">
<script type="text/javascript">
function hasRequestedVer sion() {
// check version
}

if (hasReqestedVer sion() ) {
document.write( whatever you want);
}
else {
document.write( your oopsy message);
}
</script>

<noscript>
<font color="red">Jav aScript disabled: no movies for you!</font>
</noscript>
</div>
....
<!-- the rest of your page -->
Please not that while using document.write( ) method on the loading
phase, you *do not* open stream via document.open() nor you close it
later via document.close( ).
You're using document.write( ) *only* in this case - otherwise you can
clear already loaded content or loose the remaining part of the page.

Nov 23 '05 #5
But with that I am unable to target a specific DIV take I want to write
to. I suppose I could set the display to none for the Flash ad when
closing it...instead of removing it or rewriting the HTML

Nov 23 '05 #6
VK

sn****@gmail.co m wrote:
But with that I am unable to target a specific DIV take I want to write
to. I suppose I could set the display to none for the Flash ad when
closing it...instead of removing it or rewriting the HTML


Again: these are two different situations and two very different
approaches:

[1] Page is loading.
At this moment there are no divs, element collections or document tree
- all this has to be build yet. Thus you cannot address reliably any
element by using DOM methods. All you can do is to switch (temporary)
the input stream from the server to your script by using
document.write( ) method. As you cannot address yet a particular part of
your page, document.write statements have to be in that exact place in
your document where you want to have your content added. So your script
has to be not in the document head section as usual but in the document
body:

<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body>
<div>
<script>
// here you're checking for Flash version
// and writing the needed FlashMovie tags
</script>
</div>
</body>
</html>

[2] Page is loaded
This rather proprietary moment marked by firing 'load' event and
captured by window.onload event handler.

I say "proprietar y moment" because 'load' event doesn't mean that every
single byte constituing the page content is received: some large
picture of a movie may still be loading for another minute (or an hour)
after that. So different browsers treat "load" moment a bit
differently. But all of them share the same behavior: immediately upon
"load" event being fired two very important changes are happening:
1) You can address any part of your document by using DOM methods
(getElementById etc.)
2) document.write method now doesn't add content to the page anymore
but *replaces* the current page with the document.write( ) output.

Taking into account these specifics and your original demand (preset
FlashMovie *during* the page load) I gave you the only doable solution
- see my previous post.

Nov 23 '05 #7

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

Similar topics

1
6831
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for elements, attributes, ".", and "..", plus also the "" predicate format is supported - however, only one predicate per path step is supported, and expr must be a relative path. 2. Poor performance
1
6937
by: nick | last post by:
Dear All, I have a little strange problem with using innerHTML property to update my browser document. The HTML content I am inserting in document contains images. These images are to be downloaded from the web. Well, they are downloaded and everything works, BUT: on relatively small network, I can see how these images are loaded one by one, as if requests for these images were sent sequentuially. This
1
14371
by: Izzet Pembeci | last post by:
I am trying to display some rss feeds in my homepage. To do that I am using an external script which returns smth like: document.writeln("<div ...>") document.writeln("Title of News 1") !! read from the feed ..... document.writeln("</div>") So displaying just one feed is a matter of adding the line: <script language=Javascript src="http....?rssfeed=somefeed.xml"> </script>
2
1373
by: john.kwasnik | last post by:
Hi, all -- I have several pages which use the same components over and over; I'd like to do these components as includes. I can't do server-side stuff with my ISP, so I thought I would use client-side javascript: a series of 'document.write()' statements to build the HTML fragment. This works just great in most browsers ... but Netscape 4 doesn't seem to like them. Sometimes the page doesn't display at all. Sometimes it stops...
2
1315
by: Jon | last post by:
I can't run aspnet applications after doing building it in Visual Studio. I can load the application in my browser until I make changes in vs. After that, it just hangs. I've waited up to 5-10 minutes for the page to load, but eventually have to shut off the power as everything stops responding. I've been having this problem for a while, so I'd really appreciate it if I could get a suggestion. Jon Cosby
5
3738
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button. When the user clicks the "Add another email" it will call a client side JavaScript function, add_email, which will dynamically add a new set of controls to the webpage using the innerHTML method. It appears to work perfectly fine in the browser. The...
6
3075
by: CES | last post by:
All, Visual Studio 2005 doesn't include an auto complete item for innerHTML document.getElementById("SomeID").innerHTML, is their a way of referencing the inner text of an element without using ???.innerHTML, that will work in all browsers. The following works in Firefox (Win & Mac) but not in IE(Win) or Safari. document.getElementById("SomeID").firstChild.nodeValue = "XXX"; Thanks in advance. - CES
6
3002
by: sonic | last post by:
Ok, i am sure everyone is sick of hearing about this. but i've checked about 10 different posts/sites about this issue, and they all say "use DOM" but i think there is more to be said. Perhaps I am a total newbie but the answer was not immediately obvious to me here. so.. problem: declaring doctype as xhtml will prevent myDiv.innerHtml=val from working. suggested solution:
17
34767
by: PJ | last post by:
Greetings... I have stumbled upon a small problem. I use Ajax to retrieve part of a page I need to update. I update a DIV element with the HTML contents I get from another page. It works fine. However the HTML have a SCRIPT tag that the browser should process, but
0
9843
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
10570
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...
1
10626
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,...
0
10273
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...
0
9402
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7806
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
5670
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
5849
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4474
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

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.