【问题标题】:Cancel navigation on a frame?取消框架上的导航?
【发布时间】:2011-04-06 23:18:05
【问题描述】:

假设我有一个框架集,其中包含加载 Google 的框架。当用户点击链接或按钮时,我想阻止谷歌导航到任何地方。这可能吗?

【问题讨论】:

    标签: javascript iframe hyperlink frameset frameset-iframe


    【解决方案1】:

    我认为这是不可能的。 我想到的唯一方法是在父框架集中使用一个简单的 Javascript 代码来检测何时重新加载包含 Google 主页的子框架,因为用户按下了其中的链接,然后强制子框架再次重新加载谷歌主页。比如:

    <script type="text/javascript">
       var flag_1st_time_call = true;
       function ReloadGoogleHome()
       {
          if(!flag_1st_time_call)
          {
             document.getElementById('myframe').src = "http://www.google.com";
          /* I'm not sure you can get frame with document.getElementById (I'm 
             more confortbale with IFRAMEs) anyway I think you understood the example */
          }
          flag_1st_time_call = false;
       }
    </script>
    
    <frame src="http://www.google.com" id="myframe" onload="ReloadGoogleHome();"></frame>
    

    这不会阻止用户点击链接并在一段时间内显示他们导航的页面,但突然他们会回到谷歌主页。

    另一种可能的解决方案(如果您在页面中使用 IFRAME 来显示 Google 而不是框架集)是在具有不透明度的父页面(包含 IFRAME 的页面)中创建位置绝对 div 元素并使其覆盖IFRAME,这样用户将根本无法与显示在 IFRAME 中的 Google 页面进行交互。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多