簡體   English   中英

JQuery在IFrame中獲取父URL:iframe及其父級位於不同的域中

[英]JQuery Get Parent URL in IFrame:iframe and its parent are in Different domain

我正在努力在我的iframe中獲取parenet URL(即在瀏覽器中顯示的url)。 我父站點是gslb13.aaa.com .Inside有在我加載我的網站的iframe test.elasticbeanstalk.com (注意兩者在不同的域)Onclicking smile鏈路gslb13.aaa.com 它將在iframe中加載test.elasticbeanstalk.com

要獲得我嘗試過的父網址

var url = (window.location != window.parent.location) ? document.referrer: document.location;
alert(url);

我在test.elasticbeanstalk.com的索引​​頁面中獲取父URL(在加載時)。 然后:

1)我點擊test.elasticbeanstalk.com中的“添加”按鈕轉到下一個視圖

2)在add.jspx中重復相同的代碼以獲得相同的父URL

但不幸的是我得到了test.elasticbeanstalk.com的網址(非父網址:gslb13.aaa.com)

可以任何人建議我處理這個問題嗎?

使用

document.referrer;

請參閱此

你不能。

相同的原產地安全規則禁止它。 http://en.wikipedia.org/wiki/Same-origin_policy

您需要使用get請求傳遞父頁面的URL,否則就沒有可靠的方法來獲取“父”URL。

你需要像這樣的iframe:

<script type="text/javascript">
url = encodeURIComponent(document.location.href);
document.write('<iframe src="http://test.elasticbeanstalk.com/something.php?refer='+url+'"></iframe>');
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM