Your event in event.preventDefault is undefined. You have to define it in the function that you call it in:

$("#platba").submit(function(event) {
  event.preventDefault();
});

Here is your corrected code that also works in Firefox (tested it myself on jsfiddle): https://jsfiddle.net/duzwo5bk/7/

Here is the code. Note: it doesn't work here because you cannot do popups from these snippets on StackOverflow

I also fixed the ID of your third radio :)

$(document).ready(function() {
  $("#platba").submit(function(event) {
    event.preventDefault();
    var loc = $('input[name="radio"]:checked').val();
    window.open(loc, '_blank');
    //self.close ();
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="platba">
<label class="c-input c-radio">
  <input id="radio1" name="radio" type="radio" value="https://www.paypal.com/uk/webapps/mpp/home">
  <span class="c-indicator"></span>
  <img src="img/payments/paypal.png" width="80" style="margin-top:-5px">&nbsp; Paypal
</label>
<br />
<br />
<label class="c-input c-radio">
  <input id="radio2" name="radio" type="radio" value="http://www.mbank.cz/osobni/">
  <span class="c-indicator"></span>
  <img src="img/payments/mbank.png" width="80" style="margin-top:-5px">&nbsp; mBank
</label>
<br />
<br />
<label class="c-input c-radio">
  <input id="radio3" name="radio" type="radio" value="http://example.com/platebnikarta">
  <span class="c-indicator"></span>
  <img src="img/payments/visa_mastercard.png" width="80" style="margin-top:-5px">&nbsp; Platební karta
</label>
<hr>

<button type="submit" class="btn btn-primary">Pokračovat v placení</button>
</form>

Answer from Laurens Swart on Stack Overflow
🌐
Mozilla Support
support.mozilla.org › en-US › questions › 1165910
window.open using _blank open in same window | Firefox Support Forum | Mozilla Support
A simple bit of java script that has worked for the last 10 years stopped working correctly on the latest Firefox update. The simple use of window.open( URL , "_blank") which will open the link in another tab, has stopped opening another tab and now open the link in the same window as the java script is running in. ... Might point out the link dose not return a HTML page, it returns a excel spread sheet..
Top answer
1 of 1
3

Your event in event.preventDefault is undefined. You have to define it in the function that you call it in:

$("#platba").submit(function(event) {
  event.preventDefault();
});

Here is your corrected code that also works in Firefox (tested it myself on jsfiddle): https://jsfiddle.net/duzwo5bk/7/

Here is the code. Note: it doesn't work here because you cannot do popups from these snippets on StackOverflow

I also fixed the ID of your third radio :)

$(document).ready(function() {
  $("#platba").submit(function(event) {
    event.preventDefault();
    var loc = $('input[name="radio"]:checked').val();
    window.open(loc, '_blank');
    //self.close ();
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="platba">
<label class="c-input c-radio">
  <input id="radio1" name="radio" type="radio" value="https://www.paypal.com/uk/webapps/mpp/home">
  <span class="c-indicator"></span>
  <img src="img/payments/paypal.png" width="80" style="margin-top:-5px">&nbsp; Paypal
</label>
<br />
<br />
<label class="c-input c-radio">
  <input id="radio2" name="radio" type="radio" value="http://www.mbank.cz/osobni/">
  <span class="c-indicator"></span>
  <img src="img/payments/mbank.png" width="80" style="margin-top:-5px">&nbsp; mBank
</label>
<br />
<br />
<label class="c-input c-radio">
  <input id="radio3" name="radio" type="radio" value="http://example.com/platebnikarta">
  <span class="c-indicator"></span>
  <img src="img/payments/visa_mastercard.png" width="80" style="margin-top:-5px">&nbsp; Platební karta
</label>
<hr>

<button type="submit" class="btn btn-primary">Pokračovat v placení</button>
</form>

🌐
GitHub
github.com › mozilla-mobile › firefox-ios › issues › 2481
Could not access window created using window.open('about:blank' .... code · Issue #2481 · mozilla-mobile/firefox-ios
March 2, 2017 - [Code:javascript] var win = window.open('about:blank','windownamenew','width=1,height=1,left=5,top=3'); setTimeout(function() { win.close();}, 3000); [Code:end] purpose of above code is to create new window and then close it after few seconds. but it not behave proper in firefox. here is a video to demonstrate. https://drive.google.com/file/d/0B7fztZykJUJMcldoRHB6QTBLSUE/view?usp=sharing OR firefoxBug.zip · In it you can see that safari works fine but in firefox it not.
Author   bhavnapanchal
🌐
Mozilla Bugzilla
bugzilla.mozilla.org › show_bug.cgi
1307503 - window.open not working in WebAPI Firefox Extension (unless Block PopUp Windows option is disabled)
User Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 Steps to reproduce: I have a WebAPI Extension, which needs to open new window using window.open, but it won't happen, until I disable Block PopUp Windows option inside Firefox options.
🌐
Mozilla Discourse
discourse.mozilla.org › t › window-open-behavior-after-firefox-v100 › 97380
Window.open behavior after FireFox v100 - Firefox Development - Mozilla Discourse
May 18, 2022 - Seems something changed in FireFox v100 related to Javascript open.window. The parameters for height, width, top, and left no longer seem to be honored. This is with FireFox for Linux.
🌐
Mozilla Support
support.mozilla.org › en-US › questions › 1288277
Firefox 76.0 javascript window.open() parameters ignored ...
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › open
Window: open() method - Web APIs | MDN
This feature is not Baseline because it does not work in some of the most widely-used browsers. * Some parts of this feature may have varying levels of support. ... The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name.
Find elsewhere
🌐
Mozilla Support
support.mozilla.org › en-US › questions › 1280619
Firefox 73.0: javascript function window.open() - Mozilla Support
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Mozilla Bugzilla
bugzilla.mozilla.org › show_bug.cgi
951525 - window.open() function in iframe not working in firefox
the code aspx page is to open a new window is : ScriptManager.RegisterStartupScript(Page, Page.GetType(), "popup", "window.open('" + strUrl + "','_blank','toolbar=0,location=0,menubar=0')", true); I tried this all Firefox versions. Actual results: Code is executing/working but specified url not opening in new window(or popup window) Expected results: the specified url should be opened in new window
🌐
Mozilla Discourse
discourse.mozilla.org › t › window-opener-not-being-set › 60353
Window.opener not being set - Development - Mozilla Discourse
February 8, 2020 - Hi, I am new to extension development I do not if I am missing something. I am getting the issue where firefox is not setting the window.opener of a popup window which is opened on a button click from my extension. The popup is from extension. Here is the code: window.open(browser.extension.getURL(“template.html”), ‘Title’); It opens a popup but the window.opener is not set.
🌐
Narkive
comp.lang.javascript.narkive.com › BHJ7vVMp › window-open-problem-in-firefox
window.open problem in firefox
The only way I have found to override the tab functionality is by window.open and the code I included. I can force all parts of the chrome to appear except for the illusive "extraChrome" stuff, which apparently includes the sidebar. (The code works in IE, but not in firefox.)
🌐
Coderanch
coderanch.com › t › 122392 › languages › window-opener-working-FIREFOX
window.opener not working for FIREFOX. (HTML Pages with CSS and JavaScript forum at Coderanch)
Follow the code below please. function adminLog(obj) { var loginid = encode64(obj.loginidAdmin.value); var pswd = encode64(obj.passwdAdmin.value); obj.reset(); window.opener = window.open("UserAdminPage.jsp?loginid="+loginid+"&passwd="+pswd); } function set_focus() { if(window.opener != null) { window.opener.close(); } else {} document.forms[0].reset(); document.forms[0].elements[0].focus(); } Above code works perfect for IE but doesn't work for Firefox, can any one help me on this, I want to close the window which gets open by window.open, when ever user refresh the parent window, and this work fine in IE but its not working in Firefox.
🌐
Mozilla Bugzilla
bugzilla.mozilla.org › show_bug.cgi
103843 - New windows created by javascript (window.open) should appear as tabs
We should not expose the difference between target= and window.open to the user. Actually, I think this should be two prefs. One under the popup panel: "Open a link in a new window" (or whatever). The other should be in the Tabbed Browsing panel: "Open tabs instead of windows for Windows opened by the Web page" (or whatever). Oddly enough both of these prefs exist. So it appears they don't work.
Top answer
1 of 4
14

Actually, the W3Schools documentation linked to by gabriel1836 is only a very very brief summary of functions.

And Oddly, mozilla's own developer reference CONTRADITCS this logic.

MDC / DOM / Window.open

var WindowObjectReference = window.open(strUrl, 
              strWindowName [, strWindowFeatures]); 

If a window with the name strWindowName already exists, then, instead of opening a new window, strUrl is loaded into the existing window. In this case the return value of the method is the existing window and strWindowFeatures is ignored. Providing an empty string for strUrl is a way to get a reference to an open window by its name without changing the window's location. If you want to open a new window on every call of window.open(), you should use the special value _blank for strWindowName.

However, the page also states that there are many extensions that can be installed that change this behaviour.

So either the documentation mozilla provides for people targeting their own browser is wrong or something is odd with your test system :)

Also, your current A-Href notation is bad for the web, and will infuriate users.

  <a href="http://google.com"  
     onclick="window.open( this.href, 'windowName' ); return false" >
     Text
  </a>

Is a SUBSTANTIALLY better way to do it.

Many people will instinctively 'middle click' links they want to manually open in a new tab, and having your only href as "#" infuriates them to depravity.

The "#" trick is a redundant and somewhat bad trick to stop the page going somewhere unintended, but this is only because of the lack of understanding of how to use onclick

If you return FALSE from an on-click event, it will cancel the links default action ( the default action being navigating the current page away )

Even better than this notation would be to use unintrusive javascript like so:

 <a href="google.com" rel="external" >Text</a>

and later

 <script type="text/javascript">
 jQuery(function($){ 
        $("a[rel*=external]").click(function(){ 
            window.open(this.href, 'newWindowName' ); 
            return false; 
        });
 }); 
 </script>
2 of 4
8

The window.open() function in Javascript is specifically designed to open a new window, please see: w3schools documentation. It actually sounds like IE is handling things in a non-standard way (which is hardly surprising).

If you want to relocate the existing location to a new page using Javascript, you should look at the location.replace() function.

Generally speaking I would recommend that you develop for Firefox and then fix for IE. Not only does Firefox offer better development tools but its implementation of W3C standards tends to be more correct.

🌐
Stack Overflow
stackoverflow.com › questions › 32934774 › window-open-issue-in-firefox-and-ie
Window.open issue in firefox and IE
But this is not happening in firefox and IE. Can anyone please help. <html> <head></head> <body> <p><a href="http://www.w3schools.com/html/" onclick="window.open('http://www.w3schools.com/html/', 'newwindow', 'width=1500, height=900'); return false;">Visit our HTML tutorial</a></p> </body> </html> ... Tested here, and it's working on both Firefox and Internet Explorer for me.
🌐
CopyProgramming
copyprogramming.com › howto › javascript-window-open-not-working-in-firefox
Firefox not supporting Javascript window open function - Javascript
July 25, 2023 - Window.open() used in javascript not working in firefox, 1 Answer. FireFox and Edge allow window.open just on click and in other situations (as well as ajax success) , ask the users if they want to allow opening a new window. User may also choose that the page not ask this question again.