RE: Opening a bitmap file into MSPaint from a hyperlink

Hi Terry,

if you have control over the HTML sources, you can achieve this via
JavaScript. It won't work on the web due to users' security settings, but
should work locally. Obviously, I haven't tried it out, so it's up to you to
give it a go.

First of all, you'd need to change the HREF attributes of the hyperlink.
Instead of pointing to an image file ('images/lookhere.jpg'), you need to
point to a javascript function in your HTML file, as follows: <a
href="javascript:loadPic ('images/lookhere.jpg');"> or whatever image you
want to load through the hyperlink, respectively.
This was the easiest bit.

Secondly, the javascript function loadPic needs to load the program of
choice.
Note that this is not ECMA-compatible JavaScript, it's rather Microsoft
JScript, which runs fine in Internet Explorer, but will fail to execute in
any other host (Netscape, Opera)

function loadPic (picPath) {
	var o;
	o = new ActiveXObject ("WScript.Shell");
	o.Run (picPath);
}

This function will execute the application associated with the file found at
the given path (picPath), regardless of the file type (picture, text,
executable), PROVIDED THAT:
-	the user's security settings allow the script to instantiate an ActiveX
object that gives the script access to the file system.
-	the file at the given path does exist (no idea whether relative paths from
the HTML are understood by this function, so beware of this one. You could
probably retrieve the HTML files path by using the document.location
property, but don't take my word for it, try it out)
-	there is an application associated with the file (in my case, it was the
Windows XP picture viewer)

If you want to explicitly load Paint, you can use the following line
instead:

o.Run ("pbrush \"" + picPath + "\"");

This works on Windows XP although the actual .exe is named mspaint.exe,
because "pbrush" is registered as a friendly application token (my
unofficial term) in the registry
(for everyone interested, under
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths).
Since pbrush was the name of the exe in earlier versions of Windows, and was
also located in the Windows directory back then, this should work across
platforms.

However, by no chance you will get Netscape to do that. If so, do let me
know, because this would have to be really neat code that I would not want
to miss.

In conclusion, the following things should be sorted out to ensure the above
code works as expected:

-	users' security settings may prevent your script from creating a Shell
object - you could encourage them or even implement a test routine for that
("Test <a>here</a>"), which is not as annoying as an error message would be.
After all, you set out to offer a special feature, and it is okay to have
users tweak their browsers for that, if only they are told up front.
-	find out whether relative image paths are translated accordingly in the
.Run() statement. That is a simple test, otherwise parse it from the
document.location property and combine the drive letter with the relative
image paths in the javascript function
-	editing a CD-ROMS autorun.ini (or similar) can force the launch of
Internet Explorer. A friendly statement ("this feature is only available to
users of Microsoft Internet Explorer") if someone's not using IE (can be
determined via script) would do as well.

Well, that's some usability and scripting hints from my end, happy coding!
Best, Philipp

  _____

mokka?logic technologies
Philipp Schumann

A3 Morrell Hall, John Garne Way
OX3 0TU Oxford, United Kingdom

e-mail: philipp@mokkalogic.de
Phone: (+44) 01865 485 153

  _____



-----Original Message-----
From: www-talk-request@w3.org [mailto:www-talk-request@w3.org]On Behalf
Of Terry Wilkinson
Sent: Thursday, June 26, 2003 4:44 AM
To: www-talk@w3.org
Subject: Opening a bitmap file into MSPaint from a hyperlink


Please read my original request below. I would have thought that with
all the extremely clever people out there that someone would have taken
up this little challenge. To clarify, I wish to access the bitmap files
from a hyperlink to a CD e.g. all files are stored on a CD as is the
html page with the hyperlink, rather than accessing it from the
internet.

Original Request:

I wish to create a javascript or other coding (e.g. C+ etc) , that will
allow me to OPEN a .bmp file from a hyperlink in a html page in a
browser (IE and Netscape only required), direct into: Microsoft Paint
(paint.exe for Win 2000/XP) or Microsoft Paintbrush (pbrush.exe for 9x
-ME) depending on the users operating system I need the single mouse
click on the hyperlink to determine which operating system is current
(Windows versions only), which will then identify the appropriate .exe
file (paint.exe or pbrush.exe), which will then open the .bmp file
direct into the application for editing (e.g. colouring in).

At present, such a hyperlink only opens the browser image editor by
default. I wish to bypass this totally. I also wish to bypass any
default associations that Windows may have set for .bmp files i.e. some
other image editing programs.

Can anyone help me by sharing their wisdom and knowledge with me please.

Terry


 -------------------------------
 This email message and any attachment(s) is intended only for the
 person(s) or entity(entities) to whom it is addressed. The
 information it contains may be classified as IN CONFIDENCE and may be
 legally privileged. If you are not the intended recipient any use,
 disclosure or copying of the message or attachment(s) is strictly
 prohibited. If you have received this message in error please
 notify us immediately and destroy it and any attachment(s).
 Thank you. The Ministry of Social Development accepts no
 responsibility for changes made to this message or to any
 attachment(s) after transmission from the Ministry.
 -------------------------------

Received on Thursday, 26 June 2003 00:35:24 UTC