spacer

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

home / experts / javascript / column35


Doc JavaScript's Ad Bookmarklet

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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

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