Html 有没有办法从 iframe 的内容中获取父 URL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/115526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to get the parent URL from an Iframe's content?
提问by Andrew Edvalson
I'm running an c# .net app in an iframe of an asp page on an older site. Accessing the Asp page's session information is somewhat difficult, so I'd like to make my .net app simply verify that it's being called from an approved page, or else immediately halt.
我正在旧站点上的 asp 页面的 iframe 中运行 c# .net 应用程序。访问 Asp 页面的会话信息有些困难,所以我想让我的 .net 应用程序简单地验证它是从批准的页面调用的,否则立即停止。
Is there a way for a page to find out the url of it's parent document?
有没有办法让页面找到它的父文档的 url?
采纳答案by Dan
top.location.href
But that will only work if both pages (the iframe and the main page) are being served from the same domain.
但这只有在两个页面(iframe 和主页)都来自同一个域时才有效。
回答by jumpdart
To get the URL:
获取网址:
Request.UrlReferrer....
To digest the query string:
要消化查询字符串:
NameValueCollection qs = HttpUtility.ParseQueryString(Request.UrlReferrer.Query);
回答by Raleigh Buckner
parent.location.href