Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.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
Html 根据在iFrame中打开的页面更改URL_Html_Iframe - Fatal编程技术网

Html 根据在iFrame中打开的页面更改URL

Html 根据在iFrame中打开的页面更改URL,html,iframe,Html,Iframe,我正在设计一个网站,上面有一个导航栏,下面有一个iFrame。我想做的是,用户将在这个iFrame中浏览整个网站。导航栏将一直在顶部。 当前,我的导航栏链接在我的iFrame中打开一个文档,如下所示: <li class="nav-top-links"><a class="a-nav-top-links" href="sample1.html" target="tFrame">ITEM1</a></li> 我想知道的是: 如何根据iFrame

我正在设计一个网站,上面有一个导航栏,下面有一个iFrame。我想做的是,用户将在这个iFrame中浏览整个网站。导航栏将一直在顶部。 当前,我的导航栏链接在我的iFrame中打开一个文档,如下所示:

<li class="nav-top-links"><a class="a-nav-top-links" href="sample1.html" target="tFrame">ITEM1</a></li>
  • 我想知道的是:

  • 如何根据iFrame中打开页面的链接更改浏览器中的URL?有什么类型的“监听器”我可以实现吗?所有页面将属于同一个域

  • 是否有人愿意就更好的方法提供建议


  • 您可以在iframe和父文档之间传递消息。查看此答案了解详细信息:

    您可以尝试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;
    
    相关主题: