【问题标题】:Scripted iFrame loads contents over current page instead of within an iFrame脚本化 iFrame 在当前页面而不是 iFrame 内加载内容
【发布时间】:2010-03-30 22:56:02
【问题描述】:

我正在尝试将网页加载到 iFrame 中,同时将内容栏保持在顶部,但对于我尝试加载到 iFrame 中的某些页面,内容会像我导航到该页面一样加载。

我使用以下代码来动态加载 iframe:

$('#my_iFrame').attr("src","http://www.nytimes.com/2010/03/26/opinion/26ryan.html");

这些页面上似乎有一个脚本,用于检查它是否被加载到 iframe 中,如果是,则将 document.location 更改为它自己的 url。

有没有办法绕过这样的黑客攻击,以便我可以将该网站加载到 iFrame 中?也许有什么方法可以保护 window.location 的价值?

【问题讨论】:

  • 如果有人对此有解决方案,我会很感兴趣。我可以看到解决此问题的唯一方法(特别是对于不同域上的页面)是在将页面和所有 JS 内容交付给客户端之前预先解析您自己的服务器上的所有 JS 内容,以删除对帧破坏代码的任何引用。但这对于大多数实现而言可能过于昂贵且过于复杂。
  • @Alohci 感谢您的参考!我希望有一种比那里使用的拦截策略更简单的方法。似乎有更多方法可以淘汰 iframe,然后防止 iframe 淘汰。

标签: javascript html iframe location


【解决方案1】:

通过谷歌搜索,我发现了这个:

<script>
function StopLoading()
{
if (!document.all)
{
window.stop();
}
else
{
window.document.execCommand('Stop');
}
}
</script>

<iframe onload="StopLoading()" src="http://www.someaddress.com">

但是,如果它位于不同的域中,它似乎不起作用。 你能在同一个域和不同域的页面上试试吗?

来源:http://www.steadyhealth.com/Web_Hosting_Anti_Frame_Breaker_solution_t53346.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-14
    相关资源
    最近更新 更多