javascript - 点击时检测谷歌浏览器,如果不是则重定向

标签 javascript jquery html browser detection

我想要浏览器检测按钮上的 onClick 以及结果是否为 NO。该页面将重定向到给定的 url。该按钮是表单中的submit 类型。我可以让它成为浏览器检查但当它发出警报时。重定向未执行 - 仍提交表单。

HTML

<button type="submit" onClick="isChrome()";>submit</button>

脚本

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 :http://jsfiddle.net/nobuts/g89k68ge/

最佳答案

我找到了解决方案!谢谢大家的帮助和线索。 @Ken,你的线索启发了我: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'        }
}

关于javascript - 点击时检测谷歌浏览器,如果不是则重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30858565/

相关文章:

javascript - 使用 javascript 进行火复制

javascript - 在 Jquery 中切换元素显示的可靠方法

jquery - 非常简单的 jQuery 点击画廊

jquery - 如何在选择框上显示垂直滚动条

元素之间的 HTML 异常间距

javascript - 根据 Google JavaScript 风格指南的 block 内函数声明

javascript - jQuery 缓动函数中有哪些不同的参数

JavaScript 表格不显示

html - 百分比用作坐标值时指的是什么?

php - 如何让表格内容自动以弹出形式显示