简体   繁体   English

Javascript,确定href点击是否是对javascript函数的调用

[英]Javascript, determine if an href click is a call to javascript function or not

I'm tying in to the onbeforeunload event in Javascript to disable control of the page during the unload process.我在 Javascript 中绑定onbeforeunload事件以在卸载过程中禁用页面控制。 We have a bunch of users who were editing data during this time and it was wreaking havoc on the product.在此期间,我们有一群用户正在编辑数据,这对产品造成了严重破坏。

There are a bunch of links that show up on the page that have href="javascript:....." .页面上显示了一堆带有href="javascript:....."

Clicking these links fires the disabling code, which makes the page impossible to use.单击这些链接会触发禁用代码,从而使页面无法使用。 Is there a way I can detect if the onbeforeunload event is navigating to a different page or just firing this Javascript?有什么方法可以检测onbeforeunload事件是导航到不同的页面还是只是触发这个 Javascript?

Have every href link visit a piece of javascript code which does inspection on the href contents before it is executed.让每个 href 链接访问一段 javascript 代码,该代码在执行之前检查 href 内容。

event.target.href.startsWith('javascript')

If yes, submit the request, if not, do something else.如果是,则提交请求,如果不是,则执行其他操作。

这不是最可靠的检查方法,但它适用于我的目的:

$('*:focus').attr('href')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM