473,388 Members | 976 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,388 software developers and data experts.

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 8293
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.com 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 hasReqestedVersion = DetectFlashVer(requiredMajorVersion,
requiredMinorVersion, requiredRevision);
myReference = getRefToDiv("mjsSWFf");
if((hasReqestedVersion==true) && (mjsRequire()==true)){
myReference.innerHTML = '<a
href=\"http://oascentral.onwisconsin.com/RealMedia/ads/click_lx.ads/%%PAGE%%/%%RAND%%/%%POS%%/%%CAMP%%/%%IMAGE%%/%%USER%%?\"><img
src=\"http://www.jsonline.com/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 hasRequestedVersion() {
// check version
}

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

<noscript>
<font color="red">JavaScript 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.com 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>Untitled 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 "proprietary 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
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...
1
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...
1
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...
2
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...
2
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...
5
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....
6
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...
6
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...
17
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.