Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在地址栏中显示iFrame url_Javascript_Html_Url_Iframe_Address Bar - Fatal编程技术网

Javascript 在地址栏中显示iFrame url

Javascript 在地址栏中显示iFrame url,javascript,html,url,iframe,address-bar,Javascript,Html,Url,Iframe,Address Bar,是否可以在url地址栏中包含iframe内容的url 例如,我有一个域sub.test.com,它有一个带有src to realpage.com的iframe 在逻辑上浏览页面不会改变地址栏中的任何内容,因为我们正在其他域的iframe中打开realpage 我知道不可能将整个url注入地址栏,但是如果没有主机名呢 例如,如果我在iframe中打开站点realpage.com/first.php,我希望地址栏中的url更改为sub.test.com/first.php或sub.test.com

是否可以在url地址栏中包含iframe内容的url

例如,我有一个域sub.test.com,它有一个带有src to realpage.com的iframe

在逻辑上浏览页面不会改变地址栏中的任何内容,因为我们正在其他域的iframe中打开realpage

我知道不可能将整个url注入地址栏,但是如果没有主机名呢


例如,如果我在iframe中打开站点realpage.com/first.php,我希望地址栏中的url更改为sub.test.com/first.php或sub.test.com/first

顶层框架可以更改地址,尽管不是原始部分,具体请参见pushState


为了对框架中的导航做出反应,因为它是跨源的,所以您需要使用发送要将其更改到的URL。

顶层框架可以更改地址,尽管不是源部分,请特别参见pushState


要对框架中的导航做出反应,因为它是跨源的,所以需要使用发送要将其更改为的URL。

这里有两个选项,您可以使用pushState,也可以使用哈希键导航,如果您希望使其与尚未提供pushState的浏览器兼容

pushState示例:

var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");
哈希键示例:

if ("onhashchange" in window) {  
  alert("The browser supports the hashchange event!");  
}  

function locationHashChanged() {  
  if (location.hash === "#somecoolfeature") {  
    somecoolfeature();  
  }  
}  

window.onhashchange = locationHashChanged;

有关更多信息,请参见另一个链接:

这里有两个选项,您可以使用pushState,也可以使用哈希键导航,如果您希望使其与尚未提供pushState的浏览器兼容的话

pushState示例:

var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");
哈希键示例:

if ("onhashchange" in window) {  
  alert("The browser supports the hashchange event!");  
}  

function locationHashChanged() {  
  if (location.hash === "#somecoolfeature") {  
    somecoolfeature();  
  }  
}  

window.onhashchange = locationHashChanged;

有关详细信息,请参阅另一个链接:

有关详细信息,请查看以下链接:。有关详细信息,请查看以下链接:。