javascript - How many Different ways to invoke JS inside a html Document? - Stack Overflow

So far I know, 4 different ways to define & invoke JavaScript in webpage 1.inline JS<script type

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?

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?

Share Improve this question asked Jun 13, 2012 at 17:52 Prosunjit BiswasProsunjit Biswas 1,13111 silver badges17 bronze badges 5
  • Do you want to know platform/framework specific ways? – SomeKittens Commented Jun 13, 2012 at 17:55
  • 1 What are you trying to acplish that's not handled by one of these 4 methods? – Babak Naffas Commented Jun 13, 2012 at 17:55
  • 1 @BabakNaffas This question would apply well to attempting to strip out JS from user-submitted HTML. – Niet the Dark Absol Commented Jun 13, 2012 at 17:57
  • @Kolink. But we answer the OP question, not what it can be possibly used for. He should mention what he wants to do if it's something "unique"... – gdoron Commented Jun 13, 2012 at 17:59
  • Sounds like a homework question. – Kevin Ennis Commented Jun 13, 2012 at 18:22
Add a ment  | 

2 Answers 2

Reset to default 6

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744395882a4572137.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信