Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load external javascript (having document.write) after page loads 1

Status
Not open for further replies.

shreyasree

Programmer
Aug 31, 2007
6
US
I need to load a 3-rd party javascript after my page loads.
This javascript has document.write in it - which will overwrite my page if I load it after page load. I cannot change/remove the 'document.write' in the javascript - as this is not supported by the 3rd-party.

How can I load this javascript after page loads without overwriting my page contents.

Any help is greatly appreciated.

Thanks,
Shreya
 
Any document.write statement that runs after the page finishes loading will overwrite all of the content of the current page.
Your could try an iframe.
 
Thanks for your reply!

I am new to iframe - could you please give some pointers as to how to use iframe in this scenario?

Thank you very much,
Shreya
 
Read this page

I don't exactly know what the script you are using will be doing, perhaps there is a better way to accomplish what you working on, but I would need more information to help.

I would have a separate page that has the javascript you need included on it and then load that page into an iframe on your current page. I don't exactly know what your trying to accomplish and this may not give you the functionality you are looking for.
 
Thanks once again.

This is my requirement:
I need to load a third-party bootstrap javascript onto my page, which will then cause their other js files to be loaded.

As the javascript loading takes undesirable time (due to some authentication mechanism that needs to happen before the loading), I cannot load this javascript before page load.

Now, if I want to load this javascript after the page loads, I have the problem of original page content being overwritten by a document.write in the javascript (which actually causes loading other required 3rd party files).

I basically need to be able to load the bootstrap javascript after page loads. (This javascript would have caused some more of the 3rd party files to load (using document.write)). Finally, after the javascript loading is complete, I need to call its functions from my page, to present some HTML information.

Thanks,
Shreya
 
You can ask the vendor to edit thier files so you can make better use of them or have a loading screen that gets written over and then present your content.

Or finally you can override the document.write method to suit your needs but this will only work in firefox and maybe updated versions of non IE browsers.
Code:
<html>
<head>
<script type="text/javascript">
function my_doc_write(n) {
	alert(n);
}

HTMLDocument.prototype.write= my_doc_write;

</script>

<body onload="document.write('fdasfdasfdsaFDAS');">
test
</body>
</html>
 
Thanks for your prompt reply - the options you gave make sense. I have set up a conf call with the vendor :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top