Tagged with Javascript

Detect external links & open in new window without “target blank” attribute

Following on from Jaspers comment on my blog post regarding my “newly discovered” way of creating new windows on links without using the target=”_blank” attribute, he posted a tidy bit of code based on Mootools that detects all <a> tags on his page, then opens in a new window if it starts with http:// (indicating it being an external link).

That’s cool. So I thought I would do the same using my preferred Javascript framework, jQuery. Here’s my code which has now been implemented on this site & looks like its working just fine…

$('.entry a').each(function(){
    if ($(this).attr('href').substr(0,7) == 'http://')
    {
        $(this).addClass('new-window');
    }
});

What we’re doing – top line, cycle through all <a> tags within the .entry class. Secondly, if the first 7 characters of the Href attribute within our <a> tag equals http://, then add a class to the <a> tag called new-window.

This will then be detected by my other small script on my page, as described here. Job done!

Tagged , , , ,

jQuery textarea auto-grow, auto-height

Ever wondered how sites such as Facebook create that cool auto-grow, auto-height type thing on textarea’s? Where you begin typing and the textarea automatically adjusts its own height to accommodate the text you’ve entered so far. Its awesome, and funny enough, I’ve got the same feature on the comments on this blog.

Its done by one simple, awesome jQuery script from this site.

Once downloaded and referenced in your <head> section, lob this code on your site (making sure you reference your own textarea correctly) and it’ll do its magic…

$(document).ready (function() {
    $('textarea.expanding').autogrow({
        maxHeight: 100,
	minHeight: 30,
	lineHeight: 16
    });
})

See the demo here. Awesome stuff – respect for the author, not me! :)

Tagged , ,

Flickr’s gone a bit more Ajax-y!

Word up! Flickr’s homepage has gone a little more Ajax-y than before, its a little wider too. Looks good & works well – less time loading seperate pages now since its loaded on-the-fly thanks to Ajax. Check it out…

Also, check out the regularly updated Flickr blog too, for the latest up to date news.

Tagged , ,
Follow

Get every new post delivered to your Inbox.