覆盖默认浏览器alert()方法

时间:2012-02-10 13:05:02

标签: javascript jquery-mobile

是否可以更改浏览器内置javascript方法的默认行为?

例如:

从jQuery Mobile调用alert()会创建一个非主题的对话框。覆盖浏览器的默认alert()行为并用光滑的jQuery Mobile主题对话框替换它会很棒吗?

我意识到在jQuery Mobile中创建主题对话框有很多选项,但如果可以创建一个小的javascript库来拦截对alert()的调用,那将非常好。

3 个答案:

答案 0 :(得分:0)

您无法设置JavaScript警报的样式,如果需要设置样式,请使用对话框。如果用谷歌搜索,应该有很多例子。

答案 1 :(得分:0)

检查主题对话框的jQueryMobile插件:http://dev.jtsage.com/jQM-SimpleDialog/index.html

答案 2 :(得分:0)

    Using this code you can override the default alert function in javascript and we can do actions based on the alert message. The default alert function will also work same with this.

(function () {
                var _alert = window.alert;
                window.alert = function (str) {
                    if (str == 'Invalid Sesssion')
                        window.location = "http://www.mywebsite.com/";
                    _alert(str);
                };
            })();