Help me understand [removed]void(null)

前端 未结 4 1629
旧时难觅i
旧时难觅i 2021-02-19 11:15

can someone please help me with this javascript:void(null) I found it used in link buttons as follows



        
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-19 11:50

    Appending void(0) to javascript instructions is a common trick when you use a javascript: pseudo-URL to run code. If you omit doing this, and the script returns something other than undefined, it will be treated as if it was passed to document.write - that is, the browser will navigate away to an empty page.

    There are valid applications for this trick (namely, bookmarklets should always end like this), but in the example you gave it is just wrong, for reasons already explained by others.

提交回复
热议问题