Here is my function:
function myFunction() {
var user_url = document.getElementById('pdurl').value;
if ( document.getElementById("menu").value == 'en' ) {
window.open(user_url);
}
}
Here is my function:
function myFunction() {
var user_url = document.getElementById('pdurl').value;
if ( document.getElementById("menu").value == 'en' ) {
window.open(user_url);
}
}
Window open function needs second parameter. Take a look here: https://developer.mozilla.org/en-US/docs/Web/API/window.open. This second parameter is the name of new window. It is also a good habit to make a new variable, for the new window, so You can change something in the future.
Updated code of line:
var newwindow = window.open(user_url, 'windowname');
I just realize, that target= "_blank"
or window name set to "blank"
is not so obvious (mentioned in the comments). Read that: window.open with target "_blank" in Chrome. As You can see: "_blank is not guaranteed to be a new tab or window. It's implemented differently per-browser". In that case, it is safer to use just a new name of the window, or use _tab instead. Updated my answer so the target is now just a 'windowname'
.
Update: in comments, you asked how to pass parameters to this new window url. If you mean get
parameters (that can be used in server side script later, for example php) use simple string concatenation:
user_url = user_url + '?parameter=value';
var newwindow = window.open(user_url, 'windowname');