-1

I have a menu with links:

<ul id="menu">
 <li><a href="/">Home</a></li>
 <li><a href="/Archive/all/">Archive</a></li>
 <li><a href="/About">About</a></li>
 <li><a href="/Contact">Contact</a></li>
</ul>

And if I'm at my root path (/) and click on Home menu item page reloads - how to prevent from reloading page (looking for cross-browser solution, it can be solved with js/jQuery if neccessary) if I'm currently on its target href?

lukaszkups
  • 5,790
  • 9
  • 47
  • 85

1 Answers1

0

Try this:

<ul id="menu">
    <li><a href="/" onclick="check(this.href)">Home</a></li>
    <li><a href="/Archive/all/">Archive</a></li>
    <li><a href="/About">About</a></li>
    <li><a href="/Contact">Contact</a></li>
</ul>
<script>
function check(href) {
     if(location.href != href)
         location.assign(href);
}
</script>
Marco Mercuri
  • 1,117
  • 9
  • 17