Reputation: 81
So, let's assume I have an HTML page (example.com/test.html) that has a few defined javascript functions, one of which is function play(). How would I inject javascript into the URL so that the play() function is called when the page loads?
Upvotes: 1
Views: 344
Reputation: 887285
For security reasons, this is not possible.
Otherwise, I could give you a URL to your bank that runs Javascript to transfer money to my account.
However, you can modify the page to run Javascript whenever you want, or to read parameters from the URL and execute Javascript based on the parameters.
Don't make a page that runs arbitrary Javascript from the URL, or you'll have an XSS hole.
Upvotes: 4
Reputation: 24052
You don't do this through the URL, you do this within the Javascript on the page itself:
<script language="javascript">
// Assign an anonymous function to the onload event
window.onload = function(){
// Place code to execute here.
}
</script>
Upvotes: 0