Click here to Skip to main content
12,700,555 members (34,158 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked

Gmail Image Viewer

, 15 Dec 2004
Rate this:
Please Sign up or sign in to vote.
How to add a context menu to IE that does some neat stuff in Gmail.

Before and after


The purpose of this little script was to make viewing emails with images in Gmail a bit faster. When installed using the installer, this program will add a "Gmail Image Viewer" items to the context-menu of your Internet Explorer. When selecting this menu-item while viewing a Gmail message that has image attachments, the script will run and will inline all the images in the message, so you don't have to click each image in order to view it.


The code is rooted in its ability to add an item to IE's context menu. This is done by adding a new registry key under HKCU\Software\Microsoft\Internet Explorer\MenuExt\. The registry key's name will be the name of the new context menu item, and the default value points to an HTML file that will be parsed when the user clicks the menu item.

Understanding the code

Since the code is very small, I will present it (a version of it) here in full:

var w=window.external.menuArguments;
var l=w.document.links
var len=l.length
var re_v=/
var re_d=/
var no_context=
   'onclick="event.returnValue=false" oncontextmenu="event.returnValue=false"'
var c=0

//hide thumbnails
var re_i=/
var img=w.document.getElementsByTagName("IMG")
var len2=img.length
for (var i=0;i<len2;i++) {
    if (img[i]>-1) img[i].style.display='none'

for (var i=0;i<len;i++) {
    //search for "View" followed by "Download" 
    //link (let gmail do the dirty work for us)
    if ( l[i]>-1 && i+1<len && l[i+1]>-1 ) {
            '<br><img src="'+l[i].href+'" '+ no_context +'><br>'
w.status="Gmail Image Viewer ©2004 by Nir Levy (Found " + 
    "((!c)?"no":c) + " image" + ((c!=1)?"s":"") +")"

Access to the calling page is obtained by accessing the menuArguments element of the external object. The program then gets a list of all the links in the document and defines two regular expressions that correspond to the View and Download links in a Gmail message with attachments (hopefully they will not change their links scheme anytime soon :-).

The process then continues to loop over all the links in the document and search for a View link followed by a Download link. If a pair is found then the outerHTML of the Download link is appended with the <IMG SRC> link of the download. (A separate loop hides all thumbnails before replacing the links).

The onclick and oncontextmenu events for the images are removed because they crashed my computer (I am guessing it was because of an IE5.5/NT bug - worked fine on other platforms).


  • 14th-Dec-04: Released a new version of this script (version 1.0). This version hides the thumbnails and shows the full images inline. Thumbnails are nice, but full images are sometimes nicer :-).
  • 25th-Nov-04: The people at Google finally added this feature as a built-in option in Gmail. This makes my script rather redundant, but I will leave it here as a reference for future developers.

Further Reading


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Nir Levy
Web Developer
Israel Israel
No Biography provided

You may also be interested in...


Comments and Discussions

Generalgmail already has thumbnails viewing!! Pin
ilnar30-Nov-04 19:36
memberilnar30-Nov-04 19:36 
Generalduh Pin
Nir Levy1-Dec-04 2:47
memberNir Levy1-Dec-04 2:47 
GeneralRe: duh Pin
ilnar1-Dec-04 2:56
memberilnar1-Dec-04 2:56 
Generalturbo ger on&#246;diga utsl&#228;pp Pin
Anonymous24-Nov-04 1:03
sussAnonymous24-Nov-04 1:03 
QuestionComments? Suggestions? Pin
Nir Levy23-Nov-04 7:18
memberNir Levy23-Nov-04 7:18 
AnswerRe: Comments? Suggestions? Pin
Tornn23-Nov-04 7:49
memberTornn23-Nov-04 7:49 
GeneralRe: Comments? Suggestions? Pin
qumer10123-Nov-04 23:29
memberqumer10123-Nov-04 23:29 
AnswerRe: Comments? Suggestions? Pin
GergreG23-Nov-04 13:10
memberGergreG23-Nov-04 13:10 
GeneralRe: Comments? Suggestions? Pin
diesel_travis24-Nov-04 11:39
memberdiesel_travis24-Nov-04 11:39 
AnswerRe: Comments? Suggestions? Pin
diesel_travis24-Nov-04 11:40
memberdiesel_travis24-Nov-04 11:40 
GeneralRe: Screenshot and more Pin
Nir Levy24-Nov-04 22:12
memberNir Levy24-Nov-04 22:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 15 Dec 2004
Article Copyright 2004 by Nir Levy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid