Javascript 从这个子框架获取iFrame中页面的URL
这里有很多文章,人们试图从iFrame中找到父URL 我不是想这么做,我只是想知道当前页面的URL和Javascript 出于某种原因,这似乎很难,但我看不出原因 所以,要解释清楚 我的父页面HTML看起来像Javascript 从这个子框架获取iFrame中页面的URL,javascript,jquery,url,iframe,Javascript,Jquery,Url,Iframe,这里有很多文章,人们试图从iFrame中找到父URL 我不是想这么做,我只是想知道当前页面的URL和Javascript 出于某种原因,这似乎很难,但我看不出原因 所以,要解释清楚 我的父页面HTML看起来像 <html> <body> <iframe id="mainWindow" name="mainWindow" src="myMainPage.aspx" style="border: 0; position:fixed; top:0; left:0;
<html>
<body>
<iframe id="mainWindow" name="mainWindow" src="myMainPage.aspx" style="border: 0; position:fixed; top:0; left:0; right:0; bottom:0; width:100%; height:100%"></iframe>
<iframe src="myOtherPage.aspx"></iframe>
</body>
</html>
不起作用,但这会给我父窗口的URL。(www.mysite.com/myParent.aspx)
还返回父URL
document.getElementById("mainWindow").contentWindow.location.href
不起作用,因为元素不存在于iFrame中,而存在于父元素中
我需要的是从iFrame本身加载到iFrame中的页面的当前URL。所以,非常简单
What is the URL of the page on which this javascript is loaded
这是因为我正在母版页上加载脚本,这些脚本在不同的页面上执行的操作略有不同。可能是
top.frames['mainWindow'].window.location
?或者,top.frames[window.name].window.location
在iframe
中加载脚本,而不知道正在使用的帧名称(只要它有一个).现在我弄糊涂了。我在页面中移动了脚本,现在它可以工作了。今天到此为止,但我想明天再查。
document.getElementById("mainWindow").contentWindow.location.href
What is the URL of the page on which this javascript is loaded