Get current URL from IFRAME

前端 未结 7 1480
小鲜肉
小鲜肉 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 08:53

    Hope this will help some how in your case, I suffered with the exact same problem, and just used localstorage to share the data between parent window and iframe. So in parent window you can:

    localStorage.setItem("url", myUrl);
    

    And in code where iframe source is just get this data from localstorage:

    localStorage.getItem('url');
    

    Saved me a lot of time. As far as i can see the only condition is access to the parent page code. Hope this will help someone.

提交回复
热议问题