Check if Javascript script exists on page

后端 未结 7 734
深忆病人
深忆病人 2021-02-02 10:16

I have a bookmarklet that I\'ve made and it loads a script from my server onto the users current page. However I have an if check in my script that if a condition is not met the

7条回答
  •  北荒
    北荒 (楼主)
    2021-02-02 10:40

    Just check the selector length. Here's an example using jQuery:

    if ($('script[src="http://xxx.co.uk/xxx/script.js"]').length > 0) {
        //script exists
    }
    

提交回复
热议问题