/    Sign up×
Community /Pin to ProfileBookmark

Close window if altKey event

In my situation, I have a popup window containing an image which I would like to close whenever the alt key is depressed. I found the code that allows the window to close if any alpha numeric key is pressed. Depressing the alt key however does not close the window. I understand that there is an element “altKey event”. Can that be used to close the popup window?

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzOct 01.2005 — You can't do it with just the alt key, since it has special uses.
Copy linkTweet thisAlerts:
@voyagerauthorOct 01.2005 — Okay, I can understand that. Thanx. Is it possible to write code that closes a window when either alt tab or alt esc are pressed. The idea is to prevent the user from moving to another window and capturing the image with screen capture software.

(All the other issues, such as using print screen capture, are covered by a number of encryption processes. This is the only remaining vunerability.)
Copy linkTweet thisAlerts:
@KravvitzOct 01.2005 — I forgot to try onkeydown. It doesn't work with onkeypress but does with onkeydown. Read the comment i the code.

<script type="text/javascript"><!--
function addEvent(el,etype,fn) {
if(document.addEventListener && (!window.opera || opera.version)) {
el.addEventListener(etype,fn,false);
} else if(document.attachEvent) {
el.attachEvent('on'+etype,fn);
} else {
el['on'+etype]=fn;
}
}
function keyChecker(e) {
if(window.event) { e=window.event; }
if(e.altKey) window.close();
}
// If window opened via window.open() this works in IE4+/Win, NS7.0+, and
// Firefox. It does not work in Opera or in versions of Netscape before 7
addEvent(document,'keydown',keyChecker);
// -->
</script>


Perhaps you should watermark the image.
Copy linkTweet thisAlerts:
@CharlesOct 02.2005 — Just a note. As of last month, 86% of users use MSIE ( http://www.thecounter.com/stats/2005/September/browser.php ) and only 90% of users use JavaScript ( http://www.thecounter.com/stats/2005/September/browser.php ). If you're willing to make a page that brushes off 10% why not make an MSIE specific page that brushes off 14%?
Copy linkTweet thisAlerts:
@voyagerauthorOct 02.2005 — Hi again. After some design modifications to incorporate window.open (), I was able to get the script to work. There is a small bug to work out (the window closes only after the user makes a window swap - just a tad too late). But this has potential. I know there's no way to disable alt tab, so this is the only approach that seems to have any potential.

Thanx so much for your help.
Copy linkTweet thisAlerts:
@voyagerauthorOct 02.2005 — Just a note. As of last month, 86% of users use MSIE ( http://www.thecounter.com/stats/2005/September/browser.php ) and only 90% of users use JavaScript ( http://www.thecounter.com/stats/2005/September/browser.php ). If you're willing to make a page that brushes off 10% why not make an MSIE specific page that brushes off 14%?[/QUOTE]


Hi. Interesting. Yes, for my sites that have mainly U.S. based visitors, I see that the vast majority of users have IE6. However, for my own site, which has only 50% U.S. based visitors, an entirely different picture emerges. In Europe less than have the visitors use IE. In particular, the Germans are very anti-MS. Firefox seemed to have gone past 50% earlier this year, but there has been a retreat lately.

I maintain several online galleries. The clients want to prevent copying of the images. I tried an activeX software, which works well. But I feel there are some major issues with the visitors not wanting to download the plugin. To I am looking for another solution.

Thanx for your comment.
Copy linkTweet thisAlerts:
@CharlesOct 02.2005 — Oh, you're trying to prevent the copying of images. There is only one thing that works. Don't let them post the images on the internet. No matter what else you do it will be way easy for people to copy them.
Copy linkTweet thisAlerts:
@voyagerauthorOct 02.2005 — Hi Charles. Yes, I hear you loud and clear. Save thru right click, print screen, pull it up from the temp cache, or any number of screen capture products. There are a number of ways to take the image.

The galleries in my sites have healthy sized thumbnails for universal viewing. It's the large images that are in question. These could be watermarked. But I have always felt that to be a poor route to go. And not always effective either.

If I could eliminate the alert in the script Kravvitz provided, it might work more effectively to block one route. I would feel that I can cover all the other paths to the commonly known methods of taking the images.

Thanx for taking the time to comment.
Copy linkTweet thisAlerts:
@voyagerauthorOct 02.2005 — Hi again. After some design modifications to incorporate window.open (), I was able to get the script to work. There is a small bug to work out (the window closes only after the user makes a window swap - just a tad too late). But this has potential. I know there's no way to disable alt tab, so this is the only approach that seems to have any potential.

Thanx so much for your help.[/QUOTE]



I was able to resolve the remaining conflict. it was with a java applet, which I removed. Now the script works great. Thanx for the help.
×

Success!

Help @voyager spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...