【问题标题】:Opening a specific link outside the iFrame在 iFrame 之外打开特定链接
【发布时间】:2012-06-17 10:13:05
【问题描述】:

我的网站有一个特定部分在 iFrame 中运行。现在在 iFrame 内运行的网页中,我为所有链接指定了<base target="_parent" />,它们都在 iFrame 内打开(因此,如果我要链接到我的主网站主页,它将在 iframe 内打开)。现在我希望在 iframe 之外和普通父网页内部打开一个特定链接。

如何强制该特定链接执行此操作?尝试了target="_blank",但仍然在 iFrame 内打开。

【问题讨论】:

    标签: html css iframe html-target


    【解决方案1】:

    如果您使用的是 JavaScript:

            parent.document.location = "http://www.google.com"
    

    如果您使用的是 HTML:

            <a href="http://www.google.com" target="_top">Google</a>
    

    【讨论】:

      【解决方案2】:

      我不久前遇到过这个解决方案,从那以后我就一直在使用它。使用 Javascript 函数强制链接:

      <script type='text/javascript'>
       function newWindow(){
         top.location.href = 'http://yourURL';};
      </script>
      <a href="javascript: newWindow();">YourLink</a>
      

      【讨论】:

        【解决方案3】:

        将此添加到链接onclick="window.location = 'url.html';"

        【讨论】:

        • 感谢您的回答,但它不起作用。尝试设置 href='url.html' 和不设置 href='url.html'...还有其他建议吗?
        • 通常不建议将内联 JavaScript 放入 HTML 中。更好的做法是在加载 DOM 对象(链接)后通过脚本附加此单击事件处理程序。
        【解决方案4】:

        当我制作菜单时,我会在我的 index.html 中制作一个 iframe:

        <div id="nav">
             <iframe frameBorder="0" height="35px" width="950px" src="navframe.html"></iframe>
        </div> 
        

        然后在 navframe.html 这些是我的按钮:

        <button type="button" onClick="window.parent.location='index.html'">
        Home</button>
        
        <button type="button" onClick="window.parent.location='contact.html'">
        Contact</button>
        

        这往往会奏效

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-01-30
          • 2018-05-05
          • 1970-01-01
          • 2012-08-15
          • 1970-01-01
          • 2022-09-23
          • 2012-06-27
          • 1970-01-01
          相关资源
          最近更新 更多