0

I am creating a Chrome Extension for a webpage. The page has a script execute which changes the way the page is displayed by removing or emptying elements. I found the <script> tag that I need to delete or stop from executing. Is there a way to load the page into memory, parse it remove the <script> tag and then load normally?

The only way I can remove the code via Javascript as of yet is to use Chrome Inspector to disable Javascript and then run the following code.

var scripts = document.getElementsByTagName('script');
   for (i=0, max=scripts.length; i < max; i++){
      var currentS = scripts[i];
      var xInner = currentS.innerHTML;
      if (xInner.indexOf('jsMenu1') < 1){
          currentS.parentNode.removeChild(currentS);
      }
   }
  • You could take a look at this possibly but I'm not sure if it would completely fix your issue. http://stackoverflow.com/questions/9298839/is-it-possible-to-stop-javascript-execution – mattfetz Jul 08 '15 at 22:36
  • Can you in any way alter the given ` – eithed Jul 08 '15 at 23:04
  • @mattfetz unfortunately that did not work. – IntermediateCoder Jul 09 '15 at 00:04

1 Answers1

-1

Strange Request. This will work.

$(document).ready(function() {
   var $html = $('html');
   var $script = $html.find('script#scriptToRemove');
   $script.remove();

   var htmlStr = $html.html();
   $html.html(htmlStr);
});
Allen Tellez
  • 1,198
  • 1
  • 10
  • 14