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
|