Monday, September 28, 2009

Null Links Best Practice

There have been instance were you want something to look like a link, but do something else when someone clicks is.

There are some various solutions out there, but here's the one I recommend.

Format your link like this
<a href="requirements.asp" onClick="javascript:YourJavascriptStuff;return false;">
Here's how this works: Make a page called requirements.asp, and on that page you list the minimum user requirements required for users to use your site. Obviously JavaScript is one of them.

When a user clicks the link, if they don't have a Javascript enabled browser, or have Javascript turned off, it will send them to the requirements page.

If they do have Javascript enabled, the 'return false' interrupts the HTTP call make by the href and executes the Javascript instead.

So it looks like a link, and will act like a link if there's no Javascript. If there is, the Javascript call will execute.

Friday, September 18, 2009

Add Widget to Header | Add Widget to Post in Blogger

I was working in blogger and wanted to add AdSense to it in specific places. By default, I can add a html/javascript widget to the side bar, but there was no way to add a widget to the header or to the post. Wassupwidat?

I tried editing the HTML directly, but the AdSense ads wouldn't show. I didn't want to use the built in AdSense monetize featured because that doesn't allow for channel tracking. So I poked around a bit and found they way to do it.

Add widget capability to the header

Go to the edit html and look for
<b:section class='header' id='header'>
There might be some other stuff in there, but regardless you want to edit it to read:
<b:section class='header' id='header' maxwidgets='3' showaddelement='yes' preferred='yes'>
After you do that, when you go to the layout screen you'll have an Add Widget section. Now you can put in a html/javascript widget and put your adsense in there (or anything else).

Same thing for the post section. Look for something like:
<b:section class='main' id='main' showaddelement='no'>
And replace it with:
<b:section class='main' id='main' maxwidgets='3' showaddelement='yes' preferred='yes'>
Use the maxwidgets setting to control how many widgets you want to add.