[英]How can i get html from a page that has javascript function?
When I load the page I get only a part of the code. 当我加载页面时,我只会得到部分代码。 The site is http://www.livescore.in I want to create an html page that have a variable containing the full html code. 该站点为http://www.livescore.in。我要创建一个HTML页面,该页面的变量包含完整的html代码。 Thanks in advance 提前致谢
This might be what you're after. 这可能就是您想要的。 Using jQuery you can load a full page into your site. 使用jQuery,您可以将整个页面加载到您的网站中。 Create an empty div on your page and use: 在页面上创建一个空的div并使用:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#yourDivsID").load("yourURLHere");
});
</script>
You can't access the content of an external iframe (ie an iframe which url belongs to a different domain). 您无法访问外部iframe(即url属于其他域的iframe)的内容。
So if your page is at example.com
, and it contains an iframe loading livescore.in
, the page will display the iframe and its content but the JavaScript code at example.com cannot read/write the content of the iframe. 因此,如果您的页面位于example.com
,并且包含一个加载了livescore.in
的iframe,则该页面将显示iframe及其内容,但是example.com上的JavaScript代码无法读取/写入iframe的内容。
There are solutions to this: 有解决方案:
You can use postMessage to talk to the iframe but that means that the owner of livescore.in
has agreed to communicate with you. 您可以使用的postMessage交谈的iframe但是这意味着所有者livescore.in
已同意与你沟通。
You make an ajax call to a server side script on your domain that will fetch the content for you and send it back to your JavaScript. 您对域上的服务器端脚本进行ajax调用,该脚本将为您获取内容并将其发送回JavaScript。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.