Link and execute external JavaScript file hosted on GitHub

前端 未结 15 1174
感动是毒
感动是毒 2020-11-22 04:08

When I try to change the linked reference of a local JavaScript file to a GitHub raw version my test file stops working. The error is:

Refused to exe

15条回答
  •  逝去的感伤
    2020-11-22 04:25

    My use case was to load 'bookmarklets' direclty from my Bitbucket account which has same restrictions as Github. The work around I came up with was to AJAX for the script and run eval on the response string, below snippet is based on that approach.

    
    

    Note that appending of sourceURL comment is to allow for debuging of the script within browser's developer tools.

提交回复
热议问题