所以我想要实现的是一个交互式的iframe。该iframe将与当前父url(http://parenturl.com)一致。
假设我有一个转到http://www.google.com的iframe,然后我单击了这个iframe中的一个链接。
这会将父iframe更新为http://parenturl.com#www.google.com/link2,然后url将转到您所单击的位置。
我还希望父url接受参数,这样如果我执行http://parenturl.com#bing.com,它将转到http://bing.com。
Iframe代码:
<iframe src="http://www.google.com" id="myFrame"></iframe>在iframe内的每一次点击时调用:
$('a').click(function() {
window.top.location.href = "http://www.parenturl.com#"+$(this).attr('href');
});页面加载时调用:
window.onload = function() {
var loc = 'Get url from # in parent url;
document.getElementById('myFrame').setAttribute('src', loc);
});我可以访问这两个域,但我只能在其中一个域上编辑html。
发布于 2016-11-17 05:06:19
为了防止跨站点脚本攻击,当iframe与父级位于不同的域时,不允许从iframe到父级的所有通信。您可以从父级设置iframe url。另一种方式-如在将当前url从iframe传送到父url-是不可能的。
https://stackoverflow.com/questions/40642225
复制相似问题