Register FAQ/Rules Forum Spy Search Today's Posts Mark Forums Read

Welcome to the Mac Forums forums. Please read the FAQ if you have questions. Register to participate.

 
Go Back   Mac Forums > Special Interests > Web Design and Development
TouchArcade.com - iPhone Game Reviews and News

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 27, 2005, 07:54 PM   #1
radiantm3
macrumors 6502a
 
radiantm3's Avatar
 
Join Date: Oct 2005
Location: San Jose, CA
Send a message via AIM to radiantm3
Simple DOM Scripting question. (need help)

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
Code:
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:

Code:
	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)

Code:
<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.
__________________
My website and my photos
radiantm3 is offline   Reply With Quote
Old Dec 27, 2005, 10:20 PM   #2
rendezvouscp
macrumors 68000
 
Join Date: Aug 2003
Location: Long Beach, California
Send a message via AIM to rendezvouscp
I would change:

Code:
flickrLinks[i].setAttribute("class", "pop");
to (with the rest of the code, don't mind it if you're the adventurous type ):

Code:
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
__________________
Santa Rosa 2.4 15" Matte MacBook Pro
Iron Money
rendezvouscp is offline   Reply With Quote
Old Dec 28, 2005, 01:08 AM   #3
radiantm3
Thread Starter
macrumors 6502a
 
radiantm3's Avatar
 
Join Date: Oct 2005
Location: San Jose, CA
Send a message via AIM to radiantm3
Quote:
Originally Posted by rendezvouscp
I would change:

Code:
flickrLinks[i].setAttribute("class", "pop");
to (with the rest of the code, don't mind it if you're the adventurous type ):

Code:
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.
__________________
My website and my photos
radiantm3 is offline   Reply With Quote

Reply

Mac Forums > Special Interests > Web Design and Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:24 PM.

Mac News | Mac Rumors | iPhone Game Reviews | iPhone Apps

Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 2002-2009, MacRumors.com, LLC