Javascript protocol and events
Part of javascriptthe attribute hrefis the protocol (you know, for example, http, ftp or mailto). What it does is tell the browser that the URL is actually JavaScript code.
, , , href. , onclick , href. , onclick .
, , , true () false ().
, , , addItem. false, . true, href. (.. ), .
:
<a href="http://google.com/" onclick="return false;">won't go to google.com</a>
<a href="http://google.com/" onclick="return true;">will go to google.com</a>?
, "javascript:" "href", , , <a>! :
http://gutfullofbeer.net/jslink.html
( , ) :
<a href='javascript:getLink()'>Click to go there!</a>
"getLink()" :
function getLink() {
var sel = document.getElementById('sel');
return sel.options[sel.selectedIndex].value;
}
, <select> , . <select>?
<select id='sel'>
<option value='<html><head><meta http-equiv="refresh" content="2;http://cnn.com"/></head><body>Redirecting to CNN ...</body></html>'>CNN</option>
<option value='<html><head><meta http-equiv="refresh" content="2;http://zombo.com"/><head><body>Redirecting to Zombocom ...</body></html>'>Zombocom</option>
<option value='<html><head><meta http-equiv="refresh" content="2;http://reddit.com"/></head><body>Redirecting to Reddit ...</body></html>'>Reddit</option>
</select>
- HTML . URL- , .
. , - .