0
<script type="text/javascript">
    $(document).ready(function () {

        //Check if the current URL contains '#' 
        if (document.URL.indexOf("#") == -1) {
            alert('dfjdkjfkdj');
            // Set the URL to whatever it was plus "#".
            url = document.URL + "#";
            location = "#";

            //Reload the page
            location.reload(true);

        }
    });
</script>

Above code is not working. What is the problem?

GolezTrol
  • 111,943
  • 16
  • 178
  • 202

3 Answers3

0

Setting document.URL doesn't change the url in the browser address bar. Use location.href instead:

location.href = location.href + '#';
GolezTrol
  • 111,943
  • 16
  • 178
  • 202
0

On Page load the document.ready will execute and than it will apped the URL with # without any refresh/ reload. Here is the code for this.

$(document).ready(function () {

        //Check if the current URL contains '#' 
        if (document.URL.indexOf("#") == -1) {
            alert('dfjdkjfkdj');
            // Set the URL to whatever it was plus "#".
            window.location.href = "#";

            //Reload the page
            window.location.href = window.location.href;

        }
    });

Hope this helps.

Vivek Tankaria
  • 1,325
  • 2
  • 14
  • 33
0

You need to try this. This code should work fine.

<script type="text/javascript">
    $(document).ready(function () {

        //Check if the current URL contains '#' 
        if (document.URL.indexOf("#") == -1) {
            alert('dfjdkjfkdj');
            // Set the URL to whatever it was plus "#".
            window.location.href = window.location.href + "#";

            //Reload the page
            window.location.reload(true);

        }
    });
</script>
Geeky Ninja
  • 5,922
  • 8
  • 37
  • 52