Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String is not a function on window location href [duplicate]

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/

like image 789
user3522457 Avatar asked Jul 09 '14 09:07

user3522457


People also ask

Is window location href a string?

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.

What is window location href?

Window Location Href The window.location.href property returns the URL of the current page.

How do you set a Windows href location?

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.

Does window location href reload the page?

window. location. href method returns/loads the current url. So we can use it to reload/refresh the page in javascript.


2 Answers

Try-

window.location.href = link; 

or

window.location.assign(link); 

JSFiddle

Check out the syntax of window.location here.

like image 131
Sahil Mittal Avatar answered Sep 24 '22 00:09

Sahil Mittal


Try using:

window.location.href = link; 

MDN source

like image 41
Yaje Avatar answered Sep 21 '22 00:09

Yaje