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

javascript - Getting the iframe's URL parameter from within the iframe - Stack Overflow

programmeradmin5浏览0评论

I have an iframe that is loaded on web page and I do not have permissions to access the parent page. I have access to the iframe's code. I would like to access one of the parameters of this iframe. What is the best way to achieve this?

I tried location.search but it does not give me all the parameters.

Any suggestions? Cheers.

I have an iframe that is loaded on web page and I do not have permissions to access the parent page. I have access to the iframe's code. I would like to access one of the parameters of this iframe. What is the best way to achieve this?

I tried location.search but it does not give me all the parameters.

Any suggestions? Cheers.

Share Improve this question asked Aug 19, 2016 at 15:22 NeophileNeophile 5,89017 gold badges62 silver badges107 bronze badges 5
  • Have you checked the other properties of the location object? ( href, protocol, hash, host, ... ) developer.mozilla/en-US/docs/Web/API/Location – Shilly Commented Aug 19, 2016 at 15:25
  • Yup, I have checked. None of those properties have that parameter. – Neophile Commented Aug 19, 2016 at 15:27
  • 1 When do we know that the iframe has loaded pletely? I am currently using $(window).load(function() {}); to identify that. – Neophile Commented Aug 19, 2016 at 15:31
  • Can you show some examples of what you have tried? What are the parameters returned? What is the actual URL? What are the expected parameters? – 10100111001 Commented Aug 19, 2016 at 15:53
  • window.location gives the location of the parent URL not the iframe URL. – Neophile Commented Aug 19, 2016 at 16:04
Add a ment  | 

1 Answer 1

Reset to default 4

I managed to find the answer myself and we can retrieve the iframe's URL using the following code:

document.location.href

This seems to work fine without any issues.

发布评论

评论列表(0)

  1. 暂无评论