473,802 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getEle mentByTagName(' html').innerHTM L;
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 3624


ro***********@g mail.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.getEle mentByTagName(' html').innerHTM L;
Perhaps you want
var h = document.docume ntElement.inner HTML
? Or at least
var h = document.getEle mentsByTagName( '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, insertAdjacentH TML) 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('rewritin g the page');
document.write( document.docume ntElement.inner HTML);
}
</script>
</head>
<body onload="rewrite Page();">
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
4823
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 (mySecond.js), the value defined in the second one is NOT reloaded into html page. Please help out what's wrong in my code. BTW, I use IE6.0
3
4582
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 following code from an external javascript source file, dynamically created with PHP document.write('<a href="javascript:void(0);"
3
1952
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) which is located on the same server while right frame is named "main" and contains a page (main.html) which is located on another server (server B). This page has a form named "f" with an element named "id". I want to access/read the value of...
4
12766
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 a list of values that are read as a JS array and used to populate the <option>s of a <select> in the calling page's form. Anyway, is there a way by which I can ensure, regardless of the user's browser settings, that the JS library is not used...
19
31075
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(). The problem is that after the reload, it brings you right to the top of the page. When I click 'refresh" on the original page, it brings me back to the original viewing position. Is there a way to duplicate this in from the popup window. Also,...
8
3394
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 problems. IE crashes when one refreshes the page or leave the page. This happens only after calling the Java method more than once. It does not crash if the Java method is called just once and then the page is refreshed. FireFox does not crash at all...
12
3126
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 with page reload. When user presses a button on my page most functions should clear the page and repaint it using my wholepage() function. After a couple of repaint the page goes into some error. Am I supposed to clear the div's in the page or wot?...
4
7475
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 new page that should replace an existing one. I.e when we issue an Ajax request we don't know what will be returned and analyze the response to act accordingly. Now, the way to replace the current document with a new one used to be easy and...
0
9699
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
9562
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
10538
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...
0
10305
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
10285
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
9115
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
7598
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
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2966
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.