Posting an Opera button on your website or blog is a great way to encourage people to try out the browser — but what if the visitor already uses Opera? It shows solidarity, but what if you could show them something else, something that is new to them?

You might want to replace your regular Opera banner with an ad for Opera Mini. Or show them another graphic of your own design. Or maybe not even a graphic, maybe post some sort of message, like “Opera spoken here!” or “Welcome, Opera visitors!”

It’s relatively simple to do this in PHP, or ASP, or some other server-side script…but sometimes you have to stick with static HTML. Well, client-side JavaScript can replace chunks of your page, and here’s how to do it.

1. Put the following script in a file called operalinks.js:

function replaceOperaLink(linkID) {

if(linkNode=document.getElementById(linkID)) {

if ( 0 <= navigator.userAgent.indexOf('Opera') ) {

var newButton=document.createElement('span');

newButton.innerHTML = '<a href="http://www.opera.com/">Glad to see you're using Opera!</a>';

var parentNode=linkNode.parentNode;

parentNode.replaceChild(newButton,linkNode);

}

}

}

For the innerHTML section, you can plug in a new link and banner, or a special message, or anything you want. (Just make sure that you put a backslash () in front of any apostrophes you use.)

2. Put a unique ID in the tag for your regular Opera button. Use the outermost tag that you want to replace. For example, let’s start it off with this:

<a id="OpLink" href="http://www.opera.com">Download Opera!</a>

3. Load the script in your document’s <head> section:

<script type="text/javascript" src="operalinks.js">

4. Call the function in the body onload event using the ID you chose in step 2:

<body onload="replaceOperaLink('OpLink')">

When the page loads, the script will check the visitor’s browser. If it’s Opera, it’ll replace the banner with whatever message you chose in step 1. It’s compatible with both HTML and XHTML, and you don’t need to worry about using <noscript> tags to make sure the banner still shows up for people with JavaScript disabled.

*This post originally appeared on Confessions of a Web Developer, my blog at the My Opera community.

It’s kind of redundant to post a “Get Firefox!” banner to someone already using Firefox, but it’s useful to show them an upgrade banner if they’re on an old version.  It’s also useful to show Firefox users a banner for Spread Firefox.

This can be done easily with PHP or other server-side scripting languages, but sometimes you have to use static HTML files.  That’s where client-side scripting becomes necessary.  Last month I posted some sample code that used document.write, which doesn’t work with XHTML.  (On top of that, the <noscript> blocks I used ended up causing validation errors because of their location!)

I’ve redone everything with DOM scripting, which will work with either HTML 4 or XHTML 1.0.

1. Put the following in a file called sfxlinks.js:

function replaceFirefoxLink(linkID) {
   if(linkNode=document.getElementById(linkID)) {
      var newLink=document.createElement('a');
      var newImg=document.createElement('img');
      var change=0;
      if ( 0 <= navigator.userAgent.indexOf('Firefox/0') ||
         0 <= navigator.userAgent.indexOf('Firefox/1.0') ) {
         change=1;
         newLink.setAttribute('href','YOUR_UPGRADE_LINK');
         newImg.setAttribute('alt','Upgrade to Firefox 1.5!');
         newImg.setAttribute('title','Upgrade to Firefox 1.5!');
         newImg.setAttribute('src','PATH_TO_BANNER');
      } else if (0 <= navigator.userAgent.indexOf('Firefox')) {
         change=1;
         newLink.setAttribute('href','YOUR_REFERRAL_LINK');
         newImg.setAttribute('alt','Spread Firefox!');
         newImg.setAttribute('title','Spread Firefox!');
         newImg.setAttribute('src','PATH_TO_BANNER');
      }
      if(change) {
         newLink.appendChild(newImg);
         var parentNode=linkNode.parentNode;
         parentNode.replaceChild(newLink,linkNode);
      }
   }
}

2. Use your regular Spread Firefox affiliate link and add a unique ID — let’s use id="FxLink" as an example — to the <a> tag.

3. Load the script in your document’s <head> section:
  <script type="text/javascript" src="sfxlinks.js">

4. Call the function in the body onload event using the ID you chose in step 2:
  <body onload="replaceFirefoxLink('FxLink')">

When the  page loads, the script will check the visitor’s browser to see if it’s an old version of Firefox or a current version of Firefox.  If it’s an old version, it’ll replace your standard button with your upgrade button.  If it’s a current version, it’ll replace it with a Spread Firefox button with your referral link.  Otherwise, it leaves the button alone.

This has a lot of advantages over the old version, including XHTML compatibility, no need for <noscript> blocks, easier validation, and it still degrades gracefully (if JS is unavailable or old, it leaves your normal button in place).

You can see it in action on my website, Flash: Those Who Ride the Lightning.

Originally posted on my Spread Firefox blog.

Remember when the web was young, and email was just gaining popularity in the mainstream, and there was a slew of virus hoaxes like the Good Times Virus, or It Takes Guts to Say Jesus, or Elf Bowling?

Remember painstakingly explaining to people that no, your computer couldn’t get a virus just by reading an email, you had to click on an attachment? That images were safe to open? Remember when the worst people had to worry about from web pages was unwanted cookies? Getting a virus just from looking at a web page? Preposterous! And a virus that ran up your credit card? Ridiculous!

It’s sad to think that all those “ridiculous” things are now possible—in fact, they’re commonplace. Look back at that link up there. It’s Snopes’ page on computer virus warnings. Way back when, they were all bogus. These days, most of them are real.

So what’s next? Well, they keep talking about Internet-aware appliances, so a future virus probably could “recalibrate your refrigerator’s coolness setting so all your ice cream goes melty.”

Are you troubled by ridiculous drug advertisements? Concerned that the pharaceuticals industry might be trying to unduly influence your medical care? Ask your doctor about Panexa [archive.org] today!

Aside from a great parody of those ads that list all the side effects, it really points up something that’s always bothered me about ads for prescription drugs: The person watching the commercial is generally not the person who chooses the medication.

(via News From ME)

Half-inflated Darth Vader atop a Burger King restaurant.

You may recall that Burger King had a marketing tie-in with Star Wars: Episode III: Revenge of the Sith. You may also recall that the movie came out last May. It seems that the Dark Side continues to dominate the destiny of at least one Burger King franchise. This picture was taken today (January 1, 2006).

OK, it may have deflated a bit, but 7-8 months is a bit long to keep an inflatable Darth Vader on your roof.

(10 points to the first person who identifies the reference in the title.)

Fallen Angel artwork by J.K. WoodwardAfter months of waiting, I finally picked up the newly-relaunched Fallen Angel today. This was a bit of a challenge. My usual comic store hadn’t ordered it for some reason (despite the “Fallen Angel” note on my pull list. Maybe it was still listed under DC? They figured out when Angel moved from Dark Horse to IDW, and even picked the right cover for me.

So I stopped by my other regular comic store this afternoon—the one near home instead of near work—and picked up Fallen Angel and Night Mary. In the rain. And had to get them not only back to the car, but from the car up three flights of stairs, around the apartment building, and up to the landing without getting them wet. While carrying three bags of groceries and two umbrellas.

Anyway, the book is well worth it. Peter David launches a new story with all the major players 20 years later. Some of the dynamics have changed, some are the same… and some look about to be altered significantly. Lee still fights the good fight in Bete Noire, Juris is still Magistrate, even Dolf still runs his bar. But there are new players in town, including Juris’ wife and 18-year-old son (who he thinks is his firstborn)… and a figure from Lee’s past who comes to her with a tantalizing offer (an actual “Whoa!”-out-loud moment). It looks like we may be learning the Fallen Angel’s origin soon. We’ve only just learned her real name…

Yes, this comic is good. It’s pricy at $3.99, but the story’s great, and J.K. Woodward’s art is fantastic. (See the cover? The whole thing looks like that!)

While Christmas shopping, I kept seeing things that made me wish I had brought my camera. The ridiculously giant Christmas tree at Fashion Island was not one of them; all I needed was a picture demonstrating its height.

Giant Xmas Tree

A toy store yielded a number of amusements (appropriately enough), in the form of a series of unconventional action figures—Jane Austen, Leonardo DaVinci, Mozart, Charles Dickens… and of course talking Jesus and Moses figures. And then there’s the Avenging Unicorn!

Historical Action Figures

Continue reading