PDA

View Full Version : Simple DOM Scripting question. (need help)




radiantm3
Dec 27, 2005, 06:54 PM
As you may know, there's a flickr script that adds the latest few flickr images to your website. The problem with it is that when you click on an image, it doesn't open it in a new window. I have javascript code that pops up links into new windows if it has a class="pop" attached to it. I want to add this class to the code that flickr generates.

Here is what I have, but it doesn't work:


var flickrLinks = document.flickr.getElementsByTagName("a");
for (var i=0; i<flickrLinks.length; i++){
flickrLinks[i].setAttribute("class", "pop");
}


Basically the code on my site looks like this: (I removed unnecessary code just for the illustration)


<div id="flickr">
<div class="flickr_badge_image">
<a href="#"><img /></a>
</div>
<div class="flickr_badge_image">
<a href="#"><img /></a>
</div>
<div class="flickr_badge_image">
<a href="#"><img /></a>
</div>
...
</div>


I want to add a pop class to all the link tags within the flickr div. I'm not even sure if there's anyone here who's experienced with DOM scripting, but I just thought i'd ask.

I guess another solution would be to write a script that pops up any link within the flickr div, but I'm not sure how to do that.



rendezvouscp
Dec 27, 2005, 09:20 PM
I would change:

flickrLinks[i].setAttribute("class", "pop");

to (with the rest of the code, don't mind it if you're the adventurous type ;)):


if (flickrLinks[i].className == 'pop') {

flickrLinks[i].onclick = function () {

window.open(this.getAttribute('href'),'pop');
return false;

}

flickrLinks[i].onkeypress = flickrLinks[i].onclick;
}
}


Then you can attach this as a function, and then run the function as an onload event if you'd like. Hope that helps.
-Chase

radiantm3
Dec 28, 2005, 12:08 AM
I would change:

flickrLinks[i].setAttribute("class", "pop");

to (with the rest of the code, don't mind it if you're the adventurous type ;)):


if (flickrLinks[i].className == 'pop') {

flickrLinks[i].onclick = function () {

window.open(this.getAttribute('href'),'pop');
return false;

}

flickrLinks[i].onkeypress = flickrLinks[i].onclick;
}
}


Then you can attach this as a function, and then run the function as an onload event if you'd like. Hope that helps.
-Chase
Thanks for the help. :)