G
goldtech
Hi,
Learning JS and have problem and I'll list the js file and the html
file below. The alert(links.length); shows up as 0, so somethings not
working. Help appreciated. Thanks:
js file start:
window.onload = prepareLinks();
function prepareLinks() {
alert('Inside function prepareLinks');
var links = document.getElementsByTagName('a');
alert(links.length);
for (var i=0; i<links.length; i++) {
if (links.classname == "popup") {
links.onclick = function() {
popUp(this.getAttribute("href"));
return false;
}
}
}
}
function popUp(winURL) {
window.open(winURL,"popup","width=320,height=480");
}
js file end.
Html file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html;
charset=utf-8" />
<script type="text/javascript" src="scripts/showPic2.js"></script>
</head>
<body>
<a href="http://www.yahoo.com/" class="popup">Test1</a>
<a href="http://www.bing.com/" class="popup">Test2</a>
</body>
</html>
Learning JS and have problem and I'll list the js file and the html
file below. The alert(links.length); shows up as 0, so somethings not
working. Help appreciated. Thanks:
js file start:
window.onload = prepareLinks();
function prepareLinks() {
alert('Inside function prepareLinks');
var links = document.getElementsByTagName('a');
alert(links.length);
for (var i=0; i<links.length; i++) {
if (links.classname == "popup") {
links.onclick = function() {
popUp(this.getAttribute("href"));
return false;
}
}
}
}
function popUp(winURL) {
window.open(winURL,"popup","width=320,height=480");
}
js file end.
Html file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html;
charset=utf-8" />
<script type="text/javascript" src="scripts/showPic2.js"></script>
</head>
<body>
<a href="http://www.yahoo.com/" class="popup">Test1</a>
<a href="http://www.bing.com/" class="popup">Test2</a>
</body>
</html>