我尝试了一些不同的方法,但没有任何效果,基本上我需要从 iframe 获取当前位置/url,获取我想要的部分并将其返回到 url 中的哈希值。我怎样才能在JavaScript中做到这一点?
选择正确的iframe元素,拉出src属性,做你的事情,将 src 分配给 window.location.hash
var iframe = $('iframe');
var src = iframe.attr('src');
window.location.hash = src;
EDIT
如果您想从某个位置获取动态位置iframe
你必须访问contentWindow
财产:
var iframe = $('iframe');
var contentWnd = iframe.attr('contentWindow');
var url = contentWnd.window.location.href;
window.location.hash = url;
关于获取 contentWindow 属性的有趣阅读:
http://www.bennadel.com/blog/1592-Getting-IFRAME-Window-And-Then-Document-References-With-contentWindow.htm
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)