脚本化iFrame在当前页面上而不是在iFrame中加载内容

时间:2010-03-30 22:56:02

标签: javascript html iframe location

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

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

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

看起来这些页面上有一个脚本会检查它是否被加载到iframe中,并将document.location更改为它自己的url(如果有的话)。

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

1 个答案:

答案 0 :(得分: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