Get current URL from IFRAME

前端 未结 7 1395
小鲜肉
小鲜肉 2020-11-22 08:08

Is there a simple way to get the current URL from an iframe?

The viewer would going through multiple sites. I\'m guessing I would be using something in javascript.<

相关标签:
7条回答
  • 2020-11-22 09:01

    For security reasons, you can only get the url for as long as the contents of the iframe, and the referencing javascript, are served from the same domain. As long as that is true, something like this will work:

    document.getElementById("iframe_id").contentWindow.location.href
    

    If the two domains are mismatched, you'll run into cross site reference scripting security restrictions.

    See also answers to a similar question.

    0 讨论(0)
提交回复
热议问题