开发者

jQuery Select Time picker triggers onbeforeunload every time it's clicked

I'm using the ptTimeSelect control on my asp.net page. I have some JavaScript/jQuery to handle the onbeforeunload event and display a message before the user leaves the page. However, the TimeSelect control seems to ALSO trigger the onbeforeunload event (in IE 8, I don't think it does in Firefox). This leads to confusing popups about leaving the page, when the user isn't actually leaving the page.

Anybody have an idea what is causing this? And how I can stop the event from firing when the Time Select co开发者_如何学Pythonntrol is clicked -- but keep it firing when the user actually leaves the page?

This is the control: http://pttimeselect.sourceforge.net/doc/files/jquery-ptTimeSelect-js.html


I found the solution in this Stack Overflow posting:

Internet Explorer calling window.onbeforeunload on window.open and AJAX calls

Seems that the problem is that in IE any link on the page is firing the onbeforeunload when clicked unless it's a link to the same page.

Adding a "return false" to the onclick event of each link (most of the elements in the ptTimeSelect control are links that fire off javascript but don't go anywhere). Since I didn't want to actually change the ptTimeSelect.js file in my project I attached my onclick event code to the links via jquery. Here is the code I put on my page (the page which has a Time Select control instance on it):

           $('a.ptTimeSelectHr').click(function (e) {
                return false;
            });

            $('a.ptTimeSelectMin').click(function (e) {
                return false;
            });

            $('a.ptTimeSelectHrAmPmCntr').click(function (e) {
                return false;
            });

            $('#ptTimeSelectCloseCntr').children('a').click(function (e) {
                return false;
             });

            $('#ptTimeSelectSetButton').children('a').click(function (e) {
                return false;
            });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜