I am refreshing my page using jQuery:
location.reload();
This is working great but I want to refresh the same page by passing a parameter to URL.
How can I do this by using jQuery?
Ex:
If my url is www.myweb.com
, I want to refresh this by passing a parameter like this
www.myweb.com?single
Thank you
Click these links to see these more flexible and robust solutions. They're answers to a similar question:
window.location.search = jQuery.query.set('single', true);
parse
andstringify
onwindow.location.search
These allow you to programmatically set the parameter, and, unlike the other hacks suggested for this question, won't break for URLs that already have a parameter, or if something else isn't quite what you thought might happen.
I'm using Jquery Load to handels this, works great for me. check out my code from my project. I need to refresh with arguments to put Javascript variable into php
if
window.location.hash
is empty, you cant assign to location.href a new value without using a correct function (at least tested in chrome).try the
window.location.replace
:Concision counts: I prefer
window.location = "?single";
orwindow.location += "?single";
You could simply have just done:
Unlike the other answers provided, there is no needless conditional check. If you design your project properly, you'll let the interface make the decision making and calling that statement whenever an event has been triggered.
Since there will only be one ".com" in your url, it will just replace
.com
with.com?single
. I just addedvarAppend
just in case you want to make it easier to modify the code in the future with different kinds of url variables.One other note: The
.replace
works by adding to the href since href returns a string containing the full url address information.