spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column35


Doc JavaScript's Ad Bookmarklet

C/C++ Developer (NYC)
Next Step Systems
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Eclipse Helios Update Brings New PHP Tools
Internet Explorer 9 Ups Standards Support
JBoss Portal 5 Release Easier to Use


Before we sum up this column, we would like to introduce a fun bookmarklet. Wherever you are, just execute it and the advertising banners on the page will be replaced with our own banner.

Go ahead and give it a try: Doc JavaScript Ads. Click the link to make it work on this page, or drag it to your Personal Toolbar (Navigator) or Links bar (Internet Explorer) for easy access wherever you are. Now let's take a look at the script behind the scenes:


<A HREF='javascript:void(imgs=document.images);for(i=0;i<imgs.length;i++)
{if((imgs[i].width==468)&&(imgs[i].height==60))void(imgs[i].
src="http://www.webreference.com/js/docjsad.gif");}'>Doc JavaScript Ads</A>
  // (The above three lines should be joined as one line.
  // They have been split for formatting purposes.)

First, notice the use of the void operator on statements that return explicit values (assignment statements, in our case). We assign the document.images array to a variable named imgs, and loops through all its elements. For each image, we check if its dimensions are 468x60 -- typical ad banner dimensions. If the condition evaluates to true, we change the source of the image (its src property) to http://www.webreference.com/js/docjsad.gif, the URL of Doc JavaScript's banner.

Unlike our search engine bookmarklets, this bookmarklet doesn't affect frame-based Web pages, because images in such pages are included in the frames, and are not integrated in the parent window. Therefore, running a script in the parent window's Location bar (or Address bar, in Internet Explorer) does not influence the inner frames, because the specified document object belongs to the parent's window object. Bear in mind that the term "bookmarklet" refers to javascript: bookmarks, not just ordinary javascript: links.


http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

webref The latest from WebReference.com Browse >
Flashmaps' DynamicLocator: Interactive Maps for Small Areas · Flashmaps' AreaSelector: Interactive Maps for Wide Areas · The DB Mapper: Interactive Street-level Maps of U.S. and Canada
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags


Created: February 1, 1999
Revised: February 1, 1999

URL: http://www.webreference.com/js/column35/docjs.html