Reputation: 33986
Right now I'm showing an href that redirects to a certain location, I want to redirect automatically to the same link but don't know how.
This is the link:
<script>
document.write('<a href="?s=' + geoip_city() + '"> Go </a>');
</script>
I tried with window.location but I'm messing somehow since I go literally to the name of the function.
How should I do it? Thanks
Upvotes: 0
Views: 160
Reputation: 1039180
You should use window.location.href
to redirect. So assuming you have a function which returns an url:
function geoip_city() {
...
return 'http://example.com?foo=bar';
}
you could redirect like this:
window.location.href = geoip_city();
Upvotes: 0
Reputation: 23142
Setting window.location.href
should redirect you to a new page, like this:
var url = geoip_city(); // url should be a valid url string
window.location.href = url;
Upvotes: 1