PDA

View Full Version : Unobtrusive javascript vs IE



benniaustin
03-22-2007, 06:02 PM
I'm having some problems with this unobtrusive javascript code.

The javascript turns any link with class="popup" into a popup window... in firefox. In Ie, the links just run normally.




function buildPopups() {
var popupLinks=document.getElementsByTagName('a'); //this tells the browser what tags to apply this to
for (var i=0;i<popupLinks.length;i++)
if (popupLinks[i].getAttribute("class")=="popup") { //if the link has a class of popup...
popupLinks[i].onclick = function() { //when it's clicked on...
openWindow(this.getAttribute("href")); //run the openWindow() function
return false; //kills the link so it wont fire normally
}
}
}
function openWindow(myURL) { //popup Function
window.open(myURL,'popup');
}
window.onload=buildPopups; //run the popup function when the page loads

benniaustin
03-22-2007, 06:17 PM
Alright, nevermind I got it working.

It appears IE does not support the getAttribute() function, and will require me to use .className oh well.

Twey
03-22-2007, 07:08 PM
It does support it, but you have to use getAttribute("className") rather than the standard getAttribute("class").
However, there's really no reason to use getAttribute() here...