views:

37

answers:

3

Hi,

I would want to dynamically get the DOM structure (HTML source) of a web page. I want to do some manipulations with it later. Is this possible in javascript at all?

Thanks.

+1  A: 

This is possible - it's what javascript is for! Use the document object. i.e.

document.documentElement.innerHTML
Quinn Wilson
No, this is not what i want. I want to get the DOM of another website. Say for example I need to hold the DOM of Google.com in my script
Bragboy
@Bragaadeesh: You could use AJAX to fetch the HTML source of http://google.com/
Asaph
@Asaph: can you give me a small code snippet or something as an Answer, I would accept it.
Bragboy
Well, most browsers do not allow you to use cross domain ajax requests. you'll need a library written in flash that connects to your js.
M28
+1  A: 

Yes, it is. It is a core part of browser's Javascript, DOM manipulation of your web page.

http://www.quirksmode.org/dom/intro.html

https://developer.mozilla.org/en/The_DOM_and_JavaScript

Francisco Soto
+1  A: 

Your best (and safest) bet is to either fetch the other web page server side and include it in the HTML of your page as a hidden element.

tster