Consider:
$('.b').click(function(){ var link = 'www.yahoo.com'; window.location.href(link); });
I expect it to open www.yahoo.com, but it says "string is not a function". Why?
jsFiddle: http://jsfiddle.net/V9Xat/
window. location. href is the same as the toString method of window. location , so you can choose to use either variable when using comparing as a string.
Window Location Href The window.location.href property returns the URL of the current page.
href = "https://www.example.com"; // Assigns a new URL to the current window. window. location. assign("https://www.example.com"); // Replaces the location of the current window with the new one.
window. location. href method returns/loads the current url. So we can use it to reload/refresh the page in javascript.
Try-
window.location.href = link;
or
window.location.assign(link);
JSFiddle
Check out the syntax of window.location here.
Try using:
window.location.href = link;
MDN source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With