-2

Here is my function:

function myFunction() {
    var user_url = document.getElementById('pdurl').value;  
    if ( document.getElementById("menu").value == 'en' ) {
        window.open(user_url);

    } 
}
Sid
  • 4,893
  • 14
  • 55
  • 110
import.zee
  • 945
  • 2
  • 9
  • 14
  • 1
    `function OpenInNewTab(url) { var win = window.open(url, '_blank'); win.focus(); }` – Bhargav Modi Jan 21 '15 at 06:56
  • 1
    What was your error, what is your goal, can you please provide a little bit more information, explanation. What have you tested, tried to find a solution. – Martin Jan 21 '15 at 06:57
  • 2
    Is that a question or some kind of documentation? – Werner Jan 21 '15 at 06:58
  • Thank for your time and effort in replying, really appreciate it. I am trying to create a form for my client where a user submits a URL and selects a value from the dropdown list. I wrote a code where it checks for the value selected from the dropdown and opens the amended version of the URL. – import.zee Jan 21 '15 at 07:06

1 Answers1

3

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');
Community
  • 1
  • 1
Jacek Kowalewski
  • 2,761
  • 2
  • 23
  • 36