![](/img/trans.png)
[英]Can I get the address bar url from the javascript console when the page has failed to load?
[英]Can I get the current URL without an address bar?
我使用下面的代碼來獲取當前的URL,以及其域正斜杠后的哈希ID。 我想在iframe中加載頁面的當前URL,這當然意味着沒有地址欄。 我將如何去做呢?
我現在使用的代碼:
var currentURL = (document.URL);
var part = currentURL.split("SLASH")[1];
alert(part); // alerts "XdAs2" !!!
出於安全原因,只要iframe的內容和引用javascript是從同一域提供的,您就只能獲取該url。 只要這是對的,這樣的事情就會起作用:
document.getElementById("iframe_id").contentWindow.location.href
如果兩個域不匹配,則會遇到跨站點引用腳本安全性限制。
當前URL始終在window.location
,無論是在iframe中還是在瀏覽器的根框架中。 window
對象始終引用當前視口。
示范 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.