So far I know, 4 different ways to define & invoke JavaScript in webpage
1.inline JS
<script type='text/javascript'> ... </script>
2.External JS
<script src="someURL"></script>
3.Event hander JS:
<input type="button" onclick="...javascript..."
4.JavaScript:URL
<a href="javascript: ...JS CODE...">js</a>
Is there any other ways JS can be inserted in a webpage ? Has it (how many ways) been defined in any standard Specification?
Is there any difference in the execution context of JavaScript among the mentioned 4 different ways?
There's actually quite a lot of ways to execute Javascript in HTML, all varying across browsers and platforms.
A lot of them (but not all) are listed in this infamous XSS cheatsheet.
Among less obscure ones, there are these:
<img src="javascript:...">
<body background="javascript:...">
<style>BODY{-moz-binding:url("...")}</style>
<META HTTP-EQUIV="refresh" CONTENT="0;url=javascript:...">
...and so on.
1 and 2 are basically the same, just that 2 is an external file and 1 has the content right there.
3 and 4 are along similar lines to eval
. 3 defines this
to be the element the event is on.
That's about it. If there are any other ways to include JS, I've never heard of them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With