简体   繁体   English

JavaScript从iframe获取浏览器中的网址

[英]JavaScript getting the URL in browser from an iframe

I am using a free site. 我正在使用一个免费网站。 that free site has a free app. 该免费网站有一个免费应用。 In that free app I can run PHP code from my server. 在该免费应用程序中,我可以从服务器运行PHP代码。

What JavaScript code can get me the URL of the address showing in browser called from an iframe on my server? 哪些JavaScript代码可以让我从服务器上的iframe调用的浏览器中显示的地址的URL?

Thanks -Ed 谢谢-编辑

If I understand you right, you want to get the URL of the main window from the iframe. 如果我理解正确,那么您想从iframe获取主窗口的网址。 If so (from the page in the iframe): 如果是这样(从iframe中的页面):

window.parent.location.href

NB: Security policies on browsers will not allow you to access the this property if the main window and the iframe are accessed on different domains. 注意:如果在不同的域上访问主窗口和iframe,则浏览器上的安全策略将不允许您访问此属性。

var addressBarURL = top.location.href;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM