-2

In a website, there is a js file like:

<script src="/somescript.js"></script>

somescript.js includes:

<script> 
 function hi(){alert('Hi');} 
 function sup(){alert('Sup!');} 
 hi();
 sup();    
</script>

When I enter the index page, my browser automatically runs the function hi()

How can I prevent browser to run the function hi() or change it into something i want.

Website is not mine.

Thanks

5
  • 1
    Is this your website? Commented Jun 22, 2018 at 20:06
  • There is no chance that browser launch a function by itself. You must have a <script>hi()</script> somewhere in index page Commented Jun 22, 2018 at 20:11
  • no its not my website. Commented Jun 22, 2018 at 20:13
  • sorry forgot to add hi(); Commented Jun 22, 2018 at 20:17
  • I don't think there's any way to do this. You might be able to write a browser extension that prevents loading somescript.js entirely, but I don't think it can selectively deactivate parts of it. Commented Jun 22, 2018 at 20:38

1 Answer 1

0

This will call the functions, the need to be removed from the script if you don't want them run.

 hi();
 sup(); 

You can also specify functions as exports and import them as show in this answer.

Sign up to request clarification or add additional context in comments.

1 Comment

He can't change the script, it's not his website.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.