2

I would like to collect all possible ways with which JavaScript can be defined in the web page for execution.

So far I know the basic part:

  • script tag
  • external script
  • element attributes that start with "on"
  • inside some tag: WIDTH="&{barWidth};%" ALIGN="LEFT"
  • CSS IE: style="left:expression(document.body.clientWidth/2-oDiv.offsetWidth/2);"
  • DHTML behavior in IE
  • in links: href="javascript:alert('Hi')"

Thanks!

3 Answers 3

2

In links, <a href="javascript:alert('Hi')">

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

1 Comment

Hmm, one or two year ago this code (javascript in href tag of anchor a) does not work in Opera. href attribute is not valid place for javascript.
1

More fugly things:

CSS expressions in IE — allows defining CSS properties as JavaScript expressions, which are evaluated on every possible DOM-event (on every mouse move, scroll step and so on).

DHTML Behaviors in IE — can bind .htc-files with JScript to HTML elements through CSS.

XBL bindings, Mozilla's invention, can be defined via CSS as well.

2 Comments

So this CSS expressions are only characteristic for IE. Other browser will encounter it as a error?
Other browsers just ignore unknown/erroneous CSS values.
1

I think the only one left is in the href attribute of anchors links like:

<a href="javascript:alert('hello, world!');">Say Hello</a>

This is how bookmarklets work.

This document describes all ways of embedding: http://docstore.mik.ua/orelly/webprog/jscript/ch12_02.htm

5 Comments

If it has an href attribute it is a link. It might also be an anchor if it has a name attribute, but the above shows only a link.
So this syntax is just binded to the href attribute or browsers will execute it anywhere?
@bellpeace it is binded to the href
Just for the record, the present tesnse of "bind" is "bound", not "binded".
Sorry, I am not from country where English is dominant language, so sometimes I miss tense.

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.