iframe的当前网址
问题描述:
大家好,
我需要获取iframe的当前网址(而不是iframe的第一个来源).如果iframe位于同一域中,则很容易,但iframe不会位于同一域中.另外,我不需要仅使用iframe,其他控件也可以为我工作.有什么想法吗?
感谢您的帮助.
Hi all,
I need to get the current url of iframe (not the first source of iframe). If iframe is in same domain, then it''s easy but iframe won''t be in same domain. Also, I don''t need to use only iframe anyother control will be work for me. Any ideas?
Thanks for your help.
答
这取决于您的IFrame
的当前Url是否属于同一域.
如果集合的Url具有相同的Domain,则可以尝试下面的代码来获取它.
It depends Current Url of yourIFrame
is of the same Domain or not.
If the set Url is of the same Domain then you may try below code to get it.
var currentUrl = document.getElementById("MyIframeId").contentWindow.location.href;
但是,如果将其设置为其他域网址",例如"http://www.codeProject.com",那么我怀疑您将能够获得它.
But in case if it is set to some other Domain Url, For Example - "http://www.codeProject.com", then I doubt you will be able to get it.