简体   繁体   中英

Creating a document from url javascript

This is what I've tried:

function createDocumentz() {
    var doc = document.implementation.createHTMLDocument('http://www.moviemeter.nl/film/270',null,'html');
    return doc;
}

Even though a document gets created, if I run this with Firebug it says that the body node has no childnodes, any idea why?

No, you cannot get the content from another website, this way.

If it did, it would have lead to cross site scripting.

All you would get is an empty document, due to the browser's policy, which of course has an empty body.

You can use an Iframe & set the source to the same...

Looks like you assume that you can use createHTMLDocument() to download and parse a HTML file from the URL you've passed as the first parameter. That is not the case, createHTMLDocument() always creates an empty document.

Also, the parameters you've passed to the function are those of createDocument() . createHTMLDocument() takes only one parameter, the document title. But even if you'd use createDocument() , the first parameter is the URI of the namespace , not the source document.

Unfortunately there's no way to download and manipulate external web site's HTML using JavaScript alone. The closest you can get is displaying the document in an iframe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM