javascript获取iframe网址在子域上的当前页面 [英] javascript get iframe url's current page on subdomain

查看:73
本文介绍了javascript获取iframe网址在子域上的当前页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取页面上iframe的页面URL,因为我们使用iframe来处理订购产品。然而,在我的生活中,我似乎无法得到它显示iframe的URL(显示是一个测试,因为它会自动发送电子邮件,当我看到它的作品)



代码:

 < button onClick =myFunction()>测试< / button> 
< script>
函数myFunction(){
alert(document.getElementById(iFrame)。documentWindow.location.href);
}
< / script>
< iframe src =https://iframe.mydomain.co.ukid =iFramewidth =98%height =100%>< / iframe>

此代码正在 https://products.mydomain.co.uk
正如我所说的,警报只在那里,所以我只需按下按钮即可看到它显示新的域,以便我可以做其余部分所需的内容。



有什么想法?

解决方案

在两个页面中添加document.domain ='your.domain' 。



像这样。不要忘记两个parent.top



document.domain ='corp.local';

只有父母像

document.domain ='corp';

无效。


I need to get the page url of what the iframe on my pages are on, as we use the iframe to deal with ordering products. However, for the life of me I can't seem to get it to display the iframe's URL (display is a test, as it will auto-email when I see it works)

The code:

<button onClick="myFunction()">Test</button>
<script>
function myFunction() {
alert(document.getElementById("iFrame").documentWindow.location.href);
}
</script> 
<iframe src="https://iframe.mydomain.co.uk" id="iFrame" width="98%" height="100%"></iframe>

This code is being used on https://products.mydomain.co.uk. The alert, as I said, is only there so I can just press the button to see it showing the new domain, so that I can do what is needed for the rest of it.

Any ideas?

解决方案

add document.domain = 'your.domain' in both the pages.

like this. don't forget both parent.top

document.domain = 'corp.local';

only parent like

document.domain = 'corp';

won't work.

这篇关于javascript获取iframe网址在子域上的当前页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆