background image

Content tagged with: browser

Eric's picture

I recently signed up for Google AdSense and I thought it would be fun to show ads for Internet Explorer users. Of course, you could use this tutorial for more productive purposes. Here is how I integrated this functionality into my theme.

I added 2 regions to THEME.info file:

regions[ad_left] = Ad Left
regions[ad_right] = Ad Right

I then included the regions in my theme by adding some code to my theme's page.tpl.php file:

<?php if ($ad_left): ?>
  <div id='ad_left' class='google_ads'>
    <?php print $ad_left; ?>
  </div>
<?php endif; ?>

<?php if ($ad_right): ?>
  <div id='ad_right' class='google_ads'>
    <?php print $ad_right; ?>
  </div>
<?php endif; ?>

Next, I added some CSS in my style.css theme file to absolutely position the regions in a fixed position:

.google_ads {
  position: absolute;
  bottom: 10px;
  width: 120px;
  height: 600px;
  display: none;
}

.google_ads .block {
  padding: 0;
  margin: 0;
}

body > .google_ads {
  position: fixed;
}

#ad_left {
  left: 10px; 
}

#ad_right {
  right: 10px;
}

Now that my regions were setup, I added 2 blocks containing the Google AdSense code and assigned the blocks to my new regions. You'll need to make sure the input filter you choose allows for javascript to be included.

At this point, the ads are included for every browser, but they will not be shown due to the "display: none" property I added to the "google_ads" CSS class. I added a few lines of jQuery in my theme's script.js file to show the regions for IE users:

$(document).ready(function(){
  // per IE ads
  if ($.browser.msie) {
    $('.google_ads').show();  
  }
});

If you view this page in IE, you'll see my code in action ^_^

My additional thoughts... this code executes the Google AdSense javascript regardless of your browser, but it is only shown to IE users. A more efficient method would be to use AJAX to include the javascript ONLY if the browser is IE, or of course, by implementing a server side browser detection library.

Eric's picture

Here's an (incomplete) list of the software and tools I prefer to use:

Internet Browsing
I use Firefox3 as my primary browser. Here are some of the extensions I have installed:
- Colorzilla - allows you to pick a color from a website
- Delicious Bookmarks - allows me to access, create, and search my bookmarks wherever I go
- DownloadHelper - allows you to download embedded flash. movies, objects, etc
- Firebug - the BEST tool for web development. GET IT NOW
- FireFTP - a FTP client that fits nicely into a tab in FireFox
- MeasureIt - allows you to measure distances on a website
- Web Developer - another essential tool for web development
- YSlow - a Yahoo! plugin used to evaluate and analyze page load times
I also use the following browsers for testing web apps: Safari, Flock, Camino, Opera, & ies4osx. IES4OSX allows you to install Internet Explorer on a MAC using Wine for OSX, sweet!

Development
I run OSX as my primary operating system. An operating system is useless to me if it doesn't have a fully functional shell. I use Parallels to install a Centos virtual machine (with no GUI). Centos is used to run LAMP and any other development and application services. I then connect to my linux filesystem using Samba and SSH. I use Eclipse as my primary IDE (with the PDT plugin for PHP). For database management I use Navicat and MySQL Tools. For a Subversion client I use Versions.

Other
- Quicksilver - file/application indexing to increase productivity
- Adobe Photoshop CS3 - image creation and manipulation
- Aquamacs Emacs - text editor
- FFMPEGX - video conversion
- Fugu - secure file copy
- Google Notifier - email and calendar event reminders
- IPSecuritas - VPN Connections
- Skype - Office chats, video conferencing, IMs
- iChat - IMs & video chats
- iTunes - I listen to music all day long off my iPod
- NeoOffice - OpenOffice for OSX (FREE equivalent of M$ Office)

Eric's picture

I felt it would be more secure for a user to be logged out when they close their browser. This can be done by editing your settings.php file. The default location for this is /sites/default/settings.php. Located this line of code:

<?php
ini_set
('session.cookie_lifetime'2000000);
?>

And change it to:
<?php
ini_set
('session.cookie_lifetime'0);
?>

This is the default PHP setting.