elseytd elseytd - 1 year ago 127
Javascript Question

Javascript window.open() not working right?

I am trying to open a url in the same page when the user presses a button. But when I do this code on button press:

window.open("www.google.com", "_self");

It will open to this url:


Instead of just "www.google.com" ("MYSERVER" being where the html/js file is on).

How do I get it to be just "www.google.com" instead of "MYSERVER/www.google.com"?

Any help will be appreciated.

Answer Source

Change to:

 window.open("http://www.google.com", "_self");

With Javascript (unlike typing in the browser bar), you need to use a fully qualified URL or the JS will try to make it relative to the current page.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download