Friday, January 20, 2017

javascript - String is not a function on window location href




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/


Answer



Try-



window.location.href = link;


or




window.location.assign(link);


JSFiddle



Check out the syntax of window.location here.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...