简体   繁体   English

我如何从具有javascript功能的页面获取html?

[英]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: 有解决方案:

  1. 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已同意与你沟通。

  2. 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.

相关问题 如何摆脱HTML页面中的所有JavaScript? - How can I get rid of all JavaScript from an HTML page? 如何在iframe中将页面内容获取为JavaScript中的字符串? 我想要一切 <html> 至 </html> - How can I get page content inside an iframe as string in javascript? I want everything from <html> to </html> 如何将值从父html页面转换为javascript弹出页面? - How can I get the value from a parent html page into a javascript popup page? 当模块已被 Z424516CA53B4AD4BEFZ37ED0 捆绑时,如何从 HTML 的模块中调用 javascript function? - How can I call a javascript function in a module from HTML when the module has been bundled by webpack? 我如何才能在部分HTML页面上使用Javascript函数? - How can i get my Javascript function to work on a partial html page? 如何在HTML页面中显示JavaScript函数? - How can I display a JavaScript function into the HTML page? 我如何使用angular将服务器javascript函数的结果显示到html页面 - how can i display a result from a server javascript function to a html page using angular 我如何创建一个 javascript function 从一个 HTML 页面获取文本并将其打印到另一个页面? - How can I create a javascript function that takes text from one HTML page and prints it to another? 我如何使用JavaScript将jenkins数据获取到HTML页面 - How can I get jenkins data to an HTML page using javascript 如何在 Javascript 中获取 html 页面的名称? - How can I get the name of an html page in Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM