且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

禁用后退按钮在浏览器中使用jQuery?

更新时间:2023-12-03 08:40:40

这是另一种技术,在任何网页,以禁用背面的功能。我们可以通过添加下面的网页code禁用后退导航。现在,这里的前提条件是,你必须在所有要避免用户得到从previous页书页添加此code。例如用户遵循导航第1页 - >第2页。并要停止从第2页用户回到第1页。在这种情况下,所有下面code在第1页。

code:

 < HTML>
    &所述; HEAD>
        <脚本类型=文/ JavaScript的>
             window.history.forward();
             功能noBack(){
                  window.history.forward();
             }
        < / SCRIPT>
    < / HEAD>
    &所述; BODY onload事件=noBack(); onpageshow =如果(event.persisted)noBack(); onunload的=>
    < / BODY>
< / HTML>

I would like to Disable Back button when user click on logoff for this i delete only cookies of that user not session in my application. And want to disable Back button

if(getCookie('username') == ""){
   Disable back button;// we use "window.history.redirect" for javascript i look jquery for this

}

Please help me..

This is another technique to disable the back functionality in any webpage. We can disable the back navigation by adding following code in the webpage. Now the catch here is that you have to add this code in all the pages where you want to avoid user to get back from previous page. For example user follows the navigation page1 -> page2. And you want to stop user from page2 to go back to page1. In this case all following code in page1.

CODE:

<HTML>
    <HEAD>
        <SCRIPT type="text/javascript">    
             window.history.forward();
             function noBack() { 
                  window.history.forward(); 
             }
        </SCRIPT>
    </HEAD>
    <BODY onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
    </BODY>
</HTML>