简体   繁体   English

获取外部div的内容

[英]Get content of external div

I have a new problem. 我有一个新问题。 I wan't to get the content of a div from a external webpage. 我不会从外部网页获取div的内容。 If I look in de page-source I see <div id="content">...</div> . 如果查看de page-source,我会看到<div id="content">...</div> How can I display the content with document.write() ? 如何使用document.write()显示内容?

This question is written in really bad English, but I hope you understand what I mean. 这个问题是用非常糟糕的英语写的,但是希望您能理解我的意思。

This isn't possible, because modern browser block this so called cross-site-scripting. 这是不可能的,因为现代浏览器阻止了这种所谓的跨站点脚本编写。 It would be quite a security problem if every website could load your facebook page an read personal data. 如果每个网站都可以加载您的Facebook页面读取的个人数据,那将是一个非常安全的问题。 http://en.wikipedia.org/wiki/Cross-site_scripting http://en.wikipedia.org/wiki/Cross-site_scripting

But there could be a solution using php's file_get_contents, depending on your situation http://www.php.net/manual/en/function.file-get-contents.php 但是可能会使用php的file_get_contents解决方案,具体取决于您的情况http://www.php.net/manual/en/function.file-get-contents.php

$('div#content').load('path/to/external_page.htm');

如果没有正确的脚本来为您执行请求,则无法跨域访问。

尝试将外部页面加载到iframe 1x1像素并使用内部html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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