Creating a javascript widget for other sites

前端 未结 3 2052
春和景丽
春和景丽 2020-12-07 07:17

I am looking to create a javascript \"widget\" that can be hosted on other sites. For example. I want to host the javascript code on my site:

http://scripts.my

3条回答
  •  没有蜡笔的小新
    2020-12-07 08:15

    Your script should not interfere with the rest of the page.

    • Keep the number of globals to a minimum (one namespace object should be enough)
    • Don't add properties to the built-in objects for no reason
    • Don't expect to be the only script that listen for events such as window.onload
    • If you're using for..in loops keep in mind that other scripts may have added stuff to Array.prototype
    • Take style-sheets into consideration. The default style of HTML elements may have been changed.
    • Don't update your script without reason as you risk breaking a lot of sites.

提交回复
热议问题