Display iFrame url in address bar

微笑、不失礼 提交于 2019-12-06 01:49:31
adamj

You have two options here you can either use pushState (more info) or you can use Hash key navigation (more info) if you wish to make it compatible with browsers that do not yet have pushState available.

pushState example:

var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");

Hash Key example:

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

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

window.onhashchange = locationHashChanged;

For more info here is another link: Change the URL in the browser without loading the new page using JavaScript

The top level frame can change the address (although not the origin parts) with the history api, see pushState in particular.

To do this in reaction to navigation in the frame, since it is across origins, you'd need to use postMessage to send the URL you want to change it to.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!