0

The following is html. I want to delete the first script tag. I do not want to execute first script tag. I want to modify the html of the third party. In other words, I cannot modify original html directly. Therefore I am going to solve it using grease monkey.

<html>
    <head>
        <script type='text/javascript' src='alert1.js'></script>
        <script type='text/javascript' src='alert2.js'></script>
    </head>
    <body>
    </body>
</html>

The following is grease monkey script. first script tag is deleted. However, first script tag is executed.

// ==UserScript==
// @name        testWeb
// @namespace   ddddd
// @include     https://localhost/test/a.html
// @version     1
// @grant       none
// ==/UserScript==

var script = document.getElementsByTagName('script')[0];
script.parentNode.removeChild (script);

What should I do to delete first script tag without executing it?

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
kyouno
  • 49
  • 1
  • 7
  • Don't think you can, the script tag need to be part of the DOM so you can query it and by then the http request should have started and the code will execute when that request is completed. – GillesC Dec 11 '16 at 11:46
  • you can not. Scripts are automatically executed once they are loaded. – Vladimir M Dec 11 '16 at 11:46
  • it was solved by 'Stop execution of Javascript function (client side) or tweak it' – kyouno Dec 11 '16 at 22:55

0 Answers0