Extract script tags from a HTML string

前端 未结 3 1844
我寻月下人不归
我寻月下人不归 2021-02-14 03:51

Or any other tags :)

for eg.

  
    page...
    
    

        
3条回答
  •  生来不讨喜
    2021-02-14 04:36

    You can try something like:

     function getScriptsAsText() {
       var div = document.createElement('div');
       var scripts = [];
       var scriptNodes = document.getElementsByTagName('script');
    
       for (var i=0, iLen=scriptNodes.length; i

    It returns a array of the current script elements as text, including their start and end tags.

    You might also try outerHTML, but it's not that widely supported.

提交回复
热议问题