How can I create a javascript badge or widget?

前端 未结 5 1276
鱼传尺愫
鱼传尺愫 2021-01-14 09:38

I want to create a javascript badge that displays a list of links. We host the javascript on our domain. Other sites can put an empty div tag on their page and at the botto

5条回答
  •  佛祖请我去吃肉
    2021-01-14 10:00

    You do not necessary need an initial div to fill with you link list.

    Simply create the div using document.write at the place where the script is placed.

    
    

    ... and in your script:

    var links = [
      'One',
      'Two', 
      'Three'
    ];
    
    document.write("
    " + links.join(", ") + "
    ");

    Another benefit is that you do not have to wait for the page to be fully loaded.

提交回复
热议问题