从jQuery获取iframe的内容 [英] Get content of iframe from jquery

查看:93
本文介绍了从jQuery获取iframe的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人. 我创建了页面,然后使用IFrame将其插入了另一个页面.现在,我尝试使用纯JavaScript或jquery获取该插入页面的全文.这就是我现在所拥有的,但是它不起作用...

everyone. I created my page and inserted inside another page using IFrame. Now I'm trying to get whole text of that inserted page using pure javascript or jquery. Here's what I have now, but it doesn't work...

    <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery-1.5.1.js"></script>   
<script type="text/javascript">
function getFrameContents(){
   return $("#myframe").contents().find('body');
}
</script>
</head>

<form>
<input type="button" value="CodingForums" onClick="window.alert(getFrameContents())" />
</form>

<iframe id='myframe' src="http://www.fxstreet.com/rates-charts/currency-rates/" width="100%" height="300">
  <p>Your browser does not support iframes.</p>
</iframe>

</html>

我还阅读了一些关于从不同服务器访问页面的政策.我该怎么做呢?

I've read also that there is some policy about accessing pages from different server. How can I do it properly?

推荐答案

我还阅读了一些关于从不同服务器访问页面的政策.

I've read also that there is some policy about accessing pages from different server.

是的,政策规定严格禁止.

Yes there is and the policy says it's strictly forbidden.

我该怎么做呢?

How can I do it properly?

在服务器端获取它.您可能也想使用服务器端缓存.

Fetch it on the server-side. You might want to use a server-side cache too.

这篇关于从jQuery获取iframe的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆