开发者

Get url from iframe and update hash in browser url

开发者 https://www.devze.com 2022-12-27 16:17 出处:网络
I\'ve tried a few different th开发者_开发问答ings but nothing really worked, basically i need to get the current location/url from the iframe, get the part i want and return it to the hash in the url.

I've tried a few different th开发者_开发问答ings but nothing really worked, basically i need to get the current location/url from the iframe, get the part i want and return it to the hash in the url. how can i do this in javascript?


Select the correct iframe element, pull out the src attribute, do your stuff, assign src to window.location.hash

var iframe = $('iframe');
var src    = iframe.attr('src');
window.location.hash = src;

EDIT

If you want to get dynamic location from an iframe you have to access contentWindow property:

var iframe     = $('iframe');
var contentWnd = iframe.attr('contentWindow');
var url = contentWnd.window.location.href;

window.location.hash = url;

also interesting reading on getting the contentWindow property:

http://www.bennadel.com/blog/1592-Getting-IFRAME-Window-And-Then-Document-References-With-contentWindow.htm

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号