loading remote page into DOM with javascript

Posted by scoobydoo on Stack Overflow See other posts from Stack Overflow or by scoobydoo
Published on 2009-09-24T01:08:55Z Indexed on 2010/05/29 11:52 UTC
Read the original article Hit count: 157

Filed under:
|
|
|

I am trying to write a web widget which will allow users to display customized information (from my website) in their own web page. The mechanism I want to use (for creating the web widget) is javascript.

So basically, I want to be able to write some javascript code like this (this is what the end user copies into their HTML page, to get my widget displayed in their page)

<script type="text/javascript">
/* javascript here to fetch page from remote url and insert into DOM */
</script>

I have two questions:

  1. how do I write a javascript code to fetch the page from the remote url? Ideally this will be PLAIN javascript (i.e. not using jQuery etc - since I dont want to force the user to get third party scripts jQuery which may conflict with other scripts on their page etc)

  2. The page I am fetching contains inline javascript, which gets executed in an body.onLoad event, as well as other functions which are used in response to user actions - my questions are:

i). will the body.onLoad event be triggered for the retrieved document?. ii). If the retrieved page is dumped directly into the DOM, then the document will contain two <body> sections, which is no longer valid (X)HTML - however, I need the body.onLoad event to be triggered for the page to be setup correctly, and I also need the other functions in the retrieved page, for the retrieved page to be able to respond to the user interaction.

Any suggestions/tips on how I can solve these problems?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about load