2

Is there any simple way to get all javascript code in the current page programmatically?

For example:

<html>
<head></head>
<script type="text/javascript" src="myjs.js">
<script type="text/javascript" src="userjs.js">
<script>
   //user's jscode here
</script>

</html>

And I need to put some code in myjs.js, and need to be able to get all javascript code, including the code in userjs.js, and the code in the script tag.

Actually getting the code inside the script tag is easy. But I'm stucked on how to get the code in userjs.js.

1
  • This is a security nightmare. Commented Nov 22, 2013 at 11:05

1 Answer 1

3

Just (re-)download the userjs.js file as an XMLHttpRequest. Then you can do whatever you like with the source.

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

2 Comments

What if the html and the userjs.js is from local disk in a test environment?
Then you would need to run your own HTTP server (a lightweight one would be sufficient). You could also override your browsers local file access restrictions but then you wouldn't want to surf real web pages with it so I don't recommend it.

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.