首页 文章

如何在vbscript或javascript中关闭Internet Explorer的当前选项卡

提问于
浏览
2

我想点击“注销”按钮关闭Internet Explorer的当前选项卡 . 这是在我的Web应用程序中实现的新功能 . 我的应用程序仅支持Internet Explorer . Logout按钮所在的页面是window.close()的多个页面的组合不起作用 .

我在vbscript中使用了以下代码来关闭Internet Explorer的当前浏览器窗口:

if(window.opener = Empty) then
     dim x
     x = "<%=Request.Browser.MajorVersion%>"

     if(x="6") then
        window.parent.opener = "x"
        window.parent.close
     else  
      'I need code for closing the tab here for IE7
      end if   

  end if

我使用“<%= Request.Browser.MajorVersion%>”来获取Internet Explorer的版本 . 它是IE6然后代码工作正常,因为IE6中没有选项卡功能,但如何关闭IE7的当前选项卡 . 请在这种情况下帮助我,以便我也可以关闭IE7的当前选项卡 . 事先提醒!

2 回答

  • 0

    现代浏览器不允许您关闭未使用window.open创建的窗口或选项卡 . 任何使其工作的方法都是HACK,并且在升级浏览器时必然会中断 .

  • 2

    您可以尝试关闭IE7中的选项卡: -

    window.parent.opener = "x"
        window.parent.close
    

    我遇到了同样的问题,发现这对我来说很好 . 虽然这会给你一个额外的消息(微软警告信息): -

    enter image description here

相关问题