Reputation: 98
i am trying to update url when the user hits f5 key or refresh the page using browser refresh button so that i can get the update value for key, for eg: if my current url is :
www.examplexyz.com?key=abcd
so if user hits f5 key , now i want to update the url as :
www.examplexyz.com?key=newabcd
is there any way of doing it using jquery? i tried to search it on google but what i found is disable f5. so how can i achieve this?
Upvotes: 1
Views: 2059
Reputation: 335
You can listen to the f5 key down.
$("body").keydown(function(e){
alert("keydown: "+e.which);
e.preventDefault();
});
PreventDefault() disable the default browser refreshing action. The value of F5 keydown is 116. So you can go on it in this way.
$("body").keydown(function(e){
if(e.which==116){
alert("keydown: "+e.which);
e.preventDefault();
}
});
Then you can do what you want inside the "if" scope, for example load your custom url.
window.location.href = "http://www.google.com";
I'm assuming that you know the url you want to load or at least how to build it.
Upvotes: 4