use javascript to intercept all document link clicks

前端 未结 3 862
深忆病人
深忆病人 2020-12-03 05:13

how do I intercept link clicks in document? it must be cross-platform.

I am looking for something like this:

// content is a div with innerHTML
var          


        
3条回答
  •  -上瘾入骨i
    2020-12-03 05:49

    I just found this out and it may help some people. In addition to interception, if you want to disallow the link to load another page or reload the current page. Just set the href to '#' (as in internal page ref prefix). Now you can use the link to call a function while staying at the same page.

提交回复
热议问题