简体   繁体   中英

Load an external html to string in javascript

Is it possible to load for example google.com to a javascript variable?

var html = "the html of google.com"

Is this possible?

Update: What about in an air application?

Not unless you send the source from the server.

From javascript, it will violate the Same Origin Policy . You can send the request, and you'll get a response, but the response will be empty.

If it's a page in the same domain you're in, then yes. Otherwise, not without some special URL provided by the target domain that sends you pages based on some form of special request.

You can always have your own server fetch the page and forward it to your client.

您将需要服务器端语言,因为Javascript无法进行跨域调用

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