Flickr Badge Opens New Window
February 10th, 2010 | by dod..... Published in javascript
I recently came across a simple little solution to a simply annoying artifact of the most excellent ‘Create Your Own Badge‘ from Flickr.
First off, a thank you goes out to Adam Lewis of www.adamwlewis.com for coming up with a solution, a second off (if there is such a phrase), I’m not a coder, just a humble designer that’s trying to ensure his websites function the way they should.
The problem is that when a user clicks on any of the images it displays it always opens the Flickr page in the same window, which you don’t want ideally.
So here is the solution:
- Copy the code
- Paste the Code
- Test the Code
Copy the code below and paste it below the block level element (div, table, whatever) containing your Flickr code, refresh the page, click on one of your images and that should be it.
<script type=”text/javascript”>
<!–
var oFlickrTable = document.getElementById(“flickr_badge_wrapper”);
oFlickrBadgePhotos = oFlickrTable.getElementsByTagName(“a”);
for (nBadgePhoto = 0; nBadgePhoto < oFlickrBadgePhotos.length; nBadgePhoto++) {
oFlickrBadgePhotos[nBadgePhoto].target = “external”;
}
//–>
</script>
I have used the oFlickrBadgePhotos[nBadgePhoto].target = “external”; because on the particular site I was working on it used the rel=”external” attribute, but you may be using the target=”_blank” so you’d add _blank instead i.e. oFlickrBadgePhotos[nBadgePhoto].target = “_blank”;
The only difference to the code above to what Adam has suggested is that I’ve added <script type=”text/javascript”> as opposed to just <script>, this’ll ensure that it validates properly.
You can see this code in action on the Stevie Brown website, with some of his Flickr photos in the middle of the home page.
