nich nich - 7 months ago 39
Javascript Question

How to disable #hashtag in URL

My JQM includes three

data-role="page"
.

The issue:

Now I go to another page2 from the default home page1, so the URL is
localhost/index.php#page2
. When I refresh the page, it is still in page2.

Is that a way that it can go back to
localhost/index.php
instead of current page (without any parameters)?

Answer

To disable updating URL with #hashtag, change default of changePage which handles pages transition before loading jQuery Mobile script in <head>.

Demo: #Hashtag (Disabled / Enabled)

<head>
 <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
 <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
 <script>
    $(document).on("mobileinit", function(){
     $.mobile.changePage.defaults.changeHash = false;
    });
 </script>
 <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
</head>