最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get url from iframe and update hash in browser url - Stack Overflow

programmeradmin5浏览0评论

I've tried a few different things 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?

I've tried a few different things 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?

Share Improve this question asked Apr 19, 2010 at 20:30 AdamAdam 9,46915 gold badges49 silver badges63 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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./blog/1592-Getting-IFRAME-Window-And-Then-Document-References-With-contentWindow.htm

发布评论

评论列表(0)

  1. 暂无评论