Ada*_*dam 5 javascript url hash iframe jquery
我尝试了一些不同的东西,但没有真正起作用,基本上我需要从iframe获取当前位置/网址,获取我想要的部分并将其返回到网址中的哈希值.我怎么能用javascript做到这一点?
选择正确的iframe元素,拉出src属性,做你的东西,将src分配给window.location.hash
var iframe = $('iframe');
var src = iframe.attr('src');
window.location.hash = src;
Run Code Online (Sandbox Code Playgroud)
编辑
如果您想获得动态位置,iframe
您必须访问contentWindow
属性:
var iframe = $('iframe');
var contentWnd = iframe.attr('contentWindow');
var url = contentWnd.window.location.href;
window.location.hash = url;
Run Code Online (Sandbox Code Playgroud)
获取contentWindow属性的有趣读物:
归档时间: |
|
查看次数: |
10094 次 |
最近记录: |