473,401 Members | 2,068 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,401 software developers and data experts.

reload page, document.write; external js problems

Hello,

I am dynamically editing the contents of a page and using
document.write() to reload the new, edited content. However, on the
new page, any calls to functions located in external .js files (fyi:
same domain) fail with 'object expected' (IE6). If I subsequently
reload the page, everything works. Also, if I inline this code,
everything works.
Here is an example: (called from body onload event)
(This just rewrites the page with the function to rewrite it removed;
what I'm doing is more complicated)
start
<script src="path-to-script.js">
<script>
function test() {
// I'm actually using xmlhttp GET (irrelevant)
var h = document.getElementByTagName('html').innerHTML;
h = h.replace(/start(.*?)end/m,'');
document.open();
document.write(h);
document.close();
}
</script>
end
<script>call-function-from-file(parameters);</script> <---- error
object expected

I *really* don't want to inline the code, as it is complicated and
voluminous.
I've played with other methods of executing the document.write(), using
setTimeout(), different parameters to document.open(), different
attributes for the script tag, etc... - everything is the same.
There is no evidence that the browser is even attempting to load these
files; if I remove them from the server completely, the errors are
exactly the same.

Any help is appreciated.

Thanks in advance,
Robert Waters

Nov 10 '05 #1
2 3604


ro***********@gmail.com wrote:

I am dynamically editing the contents of a page and using
document.write() to reload the new, edited content. (This just rewrites the page with the function to rewrite it removed;
what I'm doing is more complicated)
start
<script src="path-to-script.js">
Where is the closing </script> tag then?
<script>
function test() {
// I'm actually using xmlhttp GET (irrelevant)
var h = document.getElementByTagName('html').innerHTML;
Perhaps you want
var h = document.documentElement.innerHTML
? Or at least
var h = document.getElementsByTagName('html')[0].innerHTML;
? h = h.replace(/start(.*?)end/m,'');
document.open();
document.write(h);
document.close();


So the new markup written has no <html> root element at all as you use
innerHTML of the root element?

And browsers for many years by now have various object models allowing
you to replace or manipulate parts of the document, why on earth are you
trying to rewrite the complete HTML markup with some string replacement
applied?
Ever heard of the IE DOM (e.g. setting and getting innerHTML and
outerHTML on elements exposed in the DOM tree, insertAdjacentHTML) and
the W3C DOM (replaceChild, removeChild)?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 10 '05 #2
Thank you for your help, and your tips, and I am sorry to have taken up
so much of your time with mistakes related to the example that I made
for brevity's sake.

Below is a working example that will demonstrate that, when
document.write() is called using the current document's innerHTML, any
scripts referenced in an external file do not load a second time - this
causes script errors ('object expected') when the second page is
loading (using IE6).
Note that I have omitted document.open, since document.write implies it
(and it's inclusion causes no difference in IE's behaviour that I can
see):
------------test.html--------------------
<html>
<head>
<script src="script.js"></script>
<script type="text/javascript">
function rewritePage(){
alert('rewriting the page');
document.write(document.documentElement.innerHTML) ;
}
</script>
</head>
<body onload="rewritePage();">
generate a script error with document.write
<script type="text/javascript">
isScriptWorking(); // from script.js
</script>
</body>
</html>
---------script.js-------------
function isScriptWorking() {
alert('script is working');
}

Martin - if you are truly interested in why I must implement this, I
would love to explain it; I omitted it to not burden the group with my
implementation details unnecessarily. Thank you for your help so far,
it is appreciated. I understand that your time is valuable, and that
many of the problems posted on usenet can be resolved by the poster
with very little work, and it is frustrating. I realize that I could
have explained myself better, and should have used a better example
initially. -Robert
P.S. I really do believe that this is a browser issue, as I cannot find
reference to it in any of the msdn documentation, nor the DOM specs as
written by W3C, nor google, except for unanswered/worked-around posts
on this group (3 in the past several years, as archived by google).
Firefox 1.0.7 works as expected (perfectly ;) in this instance.

Nov 11 '05 #3

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

Similar topics

1
by: zdhiu | last post by:
Hi javascript gurus, I have a simple html file (simple.html) with javascript. In html page there is sentence from variable defined in .js file (myFirst.js). Once I reload another .js file...
3
by: sentinel | last post by:
Hi all, I'm trying to reload a frame from a pop-up, but really cannot figure this out. Within my index.htm file, I make a link to call a pop-up frame with a javascript function that calls the...
3
by: Morten Thorsen | last post by:
Hi frame experts c",) Hope you can help me out on this one I've got a frameset (index.html) on my server (server A) defining two frames. Left frame is named "menu" and contains a page (menu.html)...
4
by: Mark Anderson | last post by:
Sorry if this is borderline JS vs. HTML. I ask here as the success/failure if the resulting JS is key. I've a small external .JS library that allows a non code-savvy user to occasionally update...
19
by: Darren | last post by:
I have a page that opens a popup window and within the window, some databse info is submitted and the window closes. It then refreshes the original window using window.opener.location.reload(). ...
8
by: DKM | last post by:
Here are the source code files to a Java applet that utilizes LiveConnect to communicate with Javascript, and the HTML file. The thing works both in IE 6.0 and FireFox 1.4. but with some...
12
by: joe | last post by:
I have a Javascript page which needs to be dynamically changed depending on user input. The whole page is written on document.write() output. I am still new to Javascript and run into problems...
4
by: evgenyg | last post by:
Hello ! We have the following situation - when Ajax request is sent what's being returned by the server is usually an XML (which is used for DOM updates) but sometimes it's HTML which is a whole...
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
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
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
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,...
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...
0
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...
0
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,...
0
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...

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.