开发者

Is is possible to transform all js alert messages in modal window?

I'm working on an old site and i would avoid searching&replacing and i was wondering if it is possible to reaplce all alert massages function

alert('some msg');

with a jquery modal window...

i'm 开发者_C百科not asking how to do the modal window but if i can create a protoype to replace the function alert..

thanks


You can override alert:

 window.alert = function(txt) {
    // Custom handler here
 }

Note that this will be non blocking though. Code after alert will execute without waiting.


alert is special in the fact that it blocks until the user responds to the popup. Generally in JS this is a big no-no, because if you block, you'll block the entire user interface. This precludes using a jQuery modal popup as a direct replacement for alert. You need to modify the software to use callbacks instead of synchronous alerts. (Most of) JS is event-based and single-threaded, and there isn't really a way around that.

There is a function called showModalDialog which shows a modal popup window (the kind we all hate), but that's pretty much it. It originated from IE, but as Pekka pointed out it's also implemented in Firefox 3 or newer and based on a quick Google search Webkit seems to have some support for it as well. It's still not a neat in-page popup though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜