开发者

Use Javascript Alert To Keep Users On A Page

开发者 https://www.devze.com 2023-01-19 08:48 出处:网络
I am creating an internal web based application that will not be the target audience of the web. I understand the frustration of alert boxes and forcing people to do certain things.

I am creating an internal web based application that will not be the target audience of the web.

I understand the frustration of alert boxes and forcing people to do certain things.

With that said, what I am attempting to do is create a javascript function, that unless a user clicks a link on a specific page, if they try to navigate away from the page other than using a link on the page, I would like to alert them and say, sor开发者_StackOverflow中文版ry you need to click the appropriate link to exit.

What my issue is, is that I need to lock out fields, and what I can do when a user hits an edit page, im going to write to a table that user to the lockoutuser colum. If a value exist, that user can access the record if it is null, it means no one is editing the record. If someone clicks to go into that record they lock it out, my means of updating the lockoutuser colum could be ajaxy on unload of the page, but the page could be unloaded for 2 reasons, 1 the edit form is submitted or the user leaves the page.

An alert that would say, sorry you can leave this record without clicking the big red button that says unlock, and force the user without refreshing to stay on the page.

I understand the machine could crash and or an alt f4 or a brute end task on the browser will still leave me other work to unlock the record


You need to use the onunload event of the page to present a messagebox when the user tries to leave your page. Check out this example: http://www.codetoad.com/javascript/miscellaneous/onunload_event_eg.asp

0

精彩评论

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