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"> 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"> 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"> Platební karta
</label>
<hr>
<button type="submit" class="btn btn-primary">Pokračovat v placení</button>
</form>
Answer from Laurens Swart on Stack OverflowIt certainly works for me in firefox. Could it be a popup-blocker?
I tried it and also got the result is in Message box Object and also the related web page opened.
When clicking the popup blocker it will ask security warning messsage just click yes with ctrl button you will get the result.
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>
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.
try parent.window.opener instead of window.opener
Source: window.opener is null in firefox
I solved the problem by changing the code of page "first_page_in_popup.php" to:
<html>
<head>
<script type="text/javascript" >
window.opener.document.getElementById('content').value= "Test from first page in popup";
window.location.href = 'second_page_in_popup.php';
</script>
</head>
<body>
<p> First Page </p>
<input type="text" id="first" name="first">
</body>
</html>