user3586248
user3586248

Reputation: 163

Using Javascript Window.open

I am trying to code so that I use Javascript using window.open to open a url. This opens a new window as desired, BUT the url is wrong. It adds the domain url to the beginning of it. Does anyone know how I would fix this? It has to use javascript.

&TeledoccLogo = "<a onclick=""javascript:window.open('www.teladocc.com/');iAddClickStat('Benefits_Teladocc_Link');return false;"" href='#'>

URL it takes me to: https://finder-t2.int.ps.nbc.com/psp/ps/EMPLOYEE/EMPL/h/www.teladocc.com/pnc

Upvotes: 0

Views: 213

Answers (4)

Chin Leung
Chin Leung

Reputation: 14921

Add http:// to the link in your window.open. Here's a JSFiddle demo.

This one will replace the current URL:

<button onclick="window.open('http://google.com');">Demo</button>

This one will open the URL and append:

<button onclick="window.open('google.com');">Demo 2</button>

Upvotes: 3

David
David

Reputation: 218798

That's because this isn't a full URL:

www.teladocc.com

It's a relative URL. The browser has no way of knowing the difference between www.teladocc.com and, say, index.html.

If you did this:

window.open('index.html')

Then you wouldn't really expect to go to http://index.html, would you?

Use a fully-qualified URL:

window.open('http://www.teladocc.com/pnc')

Upvotes: 4

Christopher Esbrandt
Christopher Esbrandt

Reputation: 1198

You need to include the protocol in your call.

&TeledoccLogo = "<a onclick=""javascript:window.open('http://www.teladocc.com/pnc');iAddClickStat('Benefits_Teladocc_Link');return false;"" href='#'>

Upvotes: 2

Everton Mendon&#231;a
Everton Mendon&#231;a

Reputation: 688

You can add the http protocol to the url, like this:

&TeledoccLogo = "<a onclick=""javascript:window.open('http://www.teladocc.com/pnc');iAddClickStat('Benefits_Teladocc_Link');return false;"" href='#'>

Upvotes: 3

Related Questions