Reputation: 2315
I want a browser detection onClick
on a button and if the result is NO
. The page will redirect to the given url. The button is a submit
type in a form. I can make it a browser check but when It alerts. The redirect is not go - still submit form.
HTML
<button type="submit" onClick="isChrome()";>submit</button>
Script
function isChrome() {
$.browser.chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase());
event.preventDefault();
if(!$.browser.chrome){
alert('Please use only Google Chrome!');
window.location="http://www.google.com/chrome/";
return false;
stop();
}
}
FIDDLE HERE : http://jsfiddle.net/nobuts/g89k68ge/
Upvotes: 0
Views: 1532
Reputation: 356
Here's using jQuery and the submit event trigger.
https://jsfiddle.net/karanmhatre/o8d40e7v/1/
HTML
<form method="get" action="http://google.com" class="form">
<button type="submit">submit</button>
</form>
JS
$('.form').submit(function(event) {
var condition = false;
event.preventDefault();
if (!condition) {
alert('Please use only Google Chrome!');
window.location = "http://www.google.com/chrome/";
return false;
stop();
}
});
I have abstracted the code to assume the condition to be false for testing purposes.
Upvotes: 0
Reputation: 2315
I found out my solution! Thank you everyone for the help and clues. @Ken, your clue enlighten me :D
function isChrome(e) {
$chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase());
if(!$chrome){
alert('Only Google Chrome!');
//window.location="http://www.google.com/chrome/";
$('#date_form').attr('action', 'http://www.google.com/chrome/');
return false;
}else{
$('#date_form').attr('action', 'form_action_URL' }
}
Upvotes: 1
Reputation: 388
if you don't want to submit the form, you can simply create a button instead. Why bother to cancel the submit function
Upvotes: 0