Can you make a javascript function replace itself on the page with custom html?

后端 未结 4 1353
无人及你
无人及你 2021-01-13 18:42

I have some javascript which will create some sort of widget on a page. I will be giving this snippet to clients so I want them to have to do very little.

The most o

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-13 19:04

    You have to have MakeWidget defined somewhere, right? Presumably this is going to be in an external script. Why not just have the external script source just attach itself to the divContent using the window.onload method?

    This would result in this code on your client's page:

    
    

    Your makewidget.js code could then look like this:

    window.onload = function() { MakeWidget('divContent') }

    There may some issues with other scripts loading and probably some cross-browser compatibility issues but that should get you pointed in the right direction.

提交回复
热议问题