Is it the last `script` element the currently running script?

前端 未结 3 418
感动是毒
感动是毒 2020-12-02 00:19

Is it safe to assume that the last script element* in the document when the script runs** is the currently running script?

For example, I want to create

3条回答
  •  粉色の甜心
    2020-12-02 00:50

    It's not an absolute guarantee no. Check out this JSFiddle: http://jsfiddle.net/jAsek/

    
    Test case
    

    At the start

    After the first script

    At the end

    Here the alert reports the id of the injected script "early", not the id of currently running script "second".

    There's no practical difference between internal and external scripts.

提交回复
热议问题