String is not a function on window location href

JavascriptJquery

Javascript Problem Overview


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/

Javascript Solutions


Solution 1 - Javascript

Try-

window.location.href = link;

or

window.location.assign(link);

JSFiddle

Check out the syntax of window.location here.

Solution 2 - Javascript

Try using:

window.location.href = link;

MDN source

Solution 3 - Javascript

window.location.href = link;

Use this.

Solution 4 - Javascript

Either use:

window.location.href = link;

Or with .replace();:

window.location.replace(link);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3522457View Question on Stackoverflow
Solution 1 - JavascriptSahil MittalView Answer on Stackoverflow
Solution 2 - JavascriptYajeView Answer on Stackoverflow
Solution 3 - JavascriptDeepu--JavaView Answer on Stackoverflow
Solution 4 - JavascriptJaiView Answer on Stackoverflow