Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi!
I want to reload a specific page when a specific menu item is clicked using jquery or javascript
here is my menu item code:
HTML
<li id="menu-item-597" class="menu-item menu-item-type-post_type menu-item-object-page current_page_item menu-item-597 current-menu-item"><a href="http://customer.yorube.co/kameron/shop/">SHOP</a></li>


i want that when user click on above anchor tag the js function detects whether anchor tag of li#menu-item-597 is clicked or not. if clicked the reload the page.
please tell me how to do it
Thanks in advance
Posted

There are various of doing so as mentioned below :-

JS 1.0
JavaScript
window.location.href = window.location.pathname;

// This creates a history entry
If location.href is used to come to the page then we can reload the same page as below as well :-
JavaScript
onClick="history.go(0)"


JS 1.1
JavaScript
window.location.replace(window.location.pathname);

// This does not create a history entry

JS 1.2
JavaScript
window.location.reload(false);


The reload() function takes an optional parameter that can be set to true to reload from the server rather than the cache. The parameter defaults to false, so by default the page reloads from the browser's cache.

You can also reload the page by again setting the current page URL to current page URL.
Ex :-
JavaScript
onClick="window.location.href=window.location.href"



Hope this will definitely be of help to you.
 
Share this answer
 
Try this.. :)

HTML

HTML
<ul><li id="menu-item-597" onclick="CheckCondition('menu-item-597')" class="menu-item menu-item-type-post_type menu-item-object-page current_page_item menu-item-597 current-menu-item"><a href="http://customer.yorube.co/kameron/shop/">SHOP</a></li></ul>


Javascript

JavaScript
function CheckCondition(ValueString)
{
    if (ValueString == "menu-item-597") {

        location.reload();// Realods current page
        //OR
       location.href="URL what ever you want to redirect page";

    }
    else {


    }
    
}
 
Share this answer
 
Comments
saifullahiit 16-Jun-14 4:00am    
thanks for reply. i have used the following code:
<script type="text/javascript" src="code.jquery.com/jquery-1.3.2.min.js"></script>

<script type="text/javascript">

$('#menu-item-597 > a').click(function() {

alert("hi");

});

</script>
its working locally but not working on the live server.
http://customer.yorube.co/kameron if you open the link, click on enter and then click on shop menu item. you will see nothing happning.
window.location.replace('/Your Page');
in JQuery
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900