HELP! * YELLOW=global GREY=local Global HTML version of Foils prepared 21 February 97

Foil 23 The this keyword in JavaScript

From Feb 17/19 Delivered Lecture for Course CPS616 -- aJavaScript Language Objects and Frames CPS616 spring 1997 -- Feb 17 and 19 1997. by Geoffrey Fox * Important Information in IMAGE
Secs 322.5
this keyword can be very important but it is also confusing as not clear what it refers to at times.
  • Also not always clear when needed
Here is an example of use to set URL for a link
function seturl(obj) { // Put in <head></head> Part of document
obj.target = "Desiredframe"; // set frame you want it to go in!
obj.href="http://www.npac.syr.edu"; // or calculate URL dynamically
}
In normal HTML page place:
<a href="" onClick="seturl(this)" onMouseOver="window.status='URL set dynamically in routine seturl';return true" >Click Here for Dynamic URL</a>
Here this refers to link object created by <a ..> </a>
window.status is line at bottom which usually records URL
Note can specify nontrivial href and onClick but if onClick specifies href property it overrides that in HTML page


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 Fri Feb 21 1997