I am trying to make different countries in this map (http://jsfiddle.net/hansenmc/EnqP3/) open to a new tab or window. I am able to open in the same window without an issue using this code.
onRegionClick: function (element, code, region) {
if(code == 'il'){
window.open("www.mywebsite.com", "_blank");
}
When I use this code it opens in the same window and a new window simultaneously.
onRegionClick: function (element, code, region) {
if(code == 'us'){
window.open = "www.mywebsite.com, _blank";
}
Any help getting different countries to open into their own window would be greatly appreciated. I have tried solutions from other threads but none seem to work in this scenario.
CodePudding user response:
window.open
is a function, so it should be called instead of assigned to.
Instead of:
window.open = "www.mywebsite.com, _blank";
It should be:
window.open("www.mywebsite.com", "_blank");
Also, if you want the function open the URL correctly, it should include the http(s)://
prefix, otherwise it will open a relative path from the current windows location in some browsers.
The full code in your case would be:
onRegionClick: function (element, code, region) {
if(code == 'us'){
window.open("www.mywebsite.com", "_blank");
}
}
Shorter version:
onRegionClick(element, code, region) => {
if(code == 'us')
window.open("www.mywebsite.com", "_blank");
}
CodePudding user response:
You could use the Event object .preventDefault()
method on windown.open()
.