Basic HTML version of Foils prepared 23 June 1997

Foil 35 The Keyword this

From JavaScript Tutorial for Certificate Course UC Web applications Certificate -- Summer 97. by Geoffrey C. Fox, Tom Scavo


1 The this keyword is very useful but confusing since it's not always clear what it refers to
  • Not always clear when this is needed
2 Here is an example that sets the URL for a link:
3 function setURL(obj) { // Put in <head> container
4 obj.target = "Desiredframe"; // set frame
5 obj.href = "http://www.npac.syr.edu"; // set URL
6 }
7 In the body of the HTML document:
8 <a href="" onClick="setURL(this)" onMouseOver="window.status='URL set dynamically in method setURL'; return true">Click Here for Dynamic URL</a>
9 Here this refers to a link object created by <a>..</a>
10 window.status is line at bottom, which usually records URL
11 Note setURL overrides href specified in <a> tag

in Table To:


Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Apr 1 1998