HELP! * GREY=local LOCAL HTML version of Foils prepared 26 February 1996

Foil 24 The this keyword in JavaScript

From CPS616 Lectures on JavaScript CPS616 Basic Information Track for Computational Science -- Winter-Spring Semester 96. by Geoffrey C. Fox * See also color IMAGE

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 Tue Feb 18 1997