admin管理员组文章数量:1356429
I want to get the parent domain or url or hostname inside iframe javascript.
I have used document.referrer
for that, but it only works the first time. By this I mean that my iframe contains the form so when the user submits the form the iframe loads again and the referrer will bee the my iframe's domain.
Now each time my iframe loads I want the parent domain name only as I am creating the links using that.
Example:
$(".setUrl").each(function(){
var referrer = document.referrer;
this.href=referrer+"/abc.html";
});
But this only works the first time because of the reason I mentioned above. So can somebody help me overe this?
Ask me in case if more clarity required.
I want to get the parent domain or url or hostname inside iframe javascript.
I have used document.referrer
for that, but it only works the first time. By this I mean that my iframe contains the form so when the user submits the form the iframe loads again and the referrer will bee the my iframe's domain.
Now each time my iframe loads I want the parent domain name only as I am creating the links using that.
Example:
$(".setUrl").each(function(){
var referrer = document.referrer;
this.href=referrer+"/abc.html";
});
But this only works the first time because of the reason I mentioned above. So can somebody help me overe this?
Ask me in case if more clarity required.
Share Improve this question edited Jul 2, 2015 at 4:07 Dylan Valade 5,6056 gold badges44 silver badges57 bronze badges asked Feb 5, 2013 at 6:42 maheshmahesh 4,77311 gold badges46 silver badges61 bronze badges2 Answers
Reset to default 4The moment you have the parent domain URL inside the iFrame (from the document.referrer), you can store that URL in the localStorage, and then after the form is submitted, retrieve it back from the localStorage itself.
Something like:
var referringURL = document.referrer;
//store the url in localStorage
localStorage['referrer'] = referringURL;
Now after the form is submitted:
var originalReferrer = localStorage['referrer'];
//you have the original referrer back
You can do one thing for this:
- Save your parent domain / url / hostname in some hidden variable in your form.And submit that form.
- Do not set/save/use documentReferrer value from current url. When you need, use the hidden variable.
You can use any logic... e.g:
var refval=$("#documentReferrer").val();
if(refval=="")
{
$("#documentReferrer").val(referrer); //So, for the future, this will not execute...
}
本文标签: javascriptHow to get parent domain name in iframe with cross domainStack Overflow
版权声明:本文标题:javascript - How to get parent domain name in iframe with cross domain? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743945157a2566269.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论