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
-
try adding the full url with http://, teladocc.comErnesto– Ernesto2015年11月13日 20:02:10 +00:00Commented Nov 13, 2015 at 20:02
-
that is the full url. www.teladocc.com/user3586248– user35862482015年11月13日 20:02:40 +00:00Commented Nov 13, 2015 at 20:02
4 Answers 4
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')
Comments
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='#'>
Comments
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>
Comments
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='#'>