views:

41

answers:

2

I am using a image blow up simply with an overlay image and the main image. the blow up gets open when we click the small image and then if we click the opnend up blowed up image then it gets closed. Now i want that it should get closed on ecs key press.

how can i do that???

sample of my code is :-

function Blowups(arrs,flag,nums,img_nm)
{
var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
var pheight = document.getElementsByTagName('html')[0].scrollHeight;
var myHeight = document.documentElement.clientHeight;
var div1 = document.getElementById('mrgn');
var div2 = document.getElementById('div_disp');
var prev='';
var nxt='';
var scr2='';
var scr3='';
    var imgs=arrs.split(',');
    var i=(flag)-1;
    var k=0;
    var m=0;
    src1='http://www.a.in/im/'+imgs[i];
            if(flag != 1)
                prev="<a href=\"blah blah\">&laquo; Prev</a>";
            if(flag != nums)
                nxt="<a href=\"blah blah\">Next &raquo;</a>";
document.getElementById('blah blah').innerHTML='<td><img src='+src1+'><div><p>'+nxt+'</p><p>'+prev+'</p></div></td>';
div2.className ='blah blah';div2.style.height =pheight+'px';
div1.style.marginTop =h+'px';div1.style.height =myHeight+'px';
}
+1  A: 

Add this where it best fits:

<script type="text/javascript">
 window.onkeyup = function (event) {
  if (event.keyCode == 27) {
   window.close();
  }
 }
</script>

Changing window.close(); to destroy or hide your <div> tag containing the blown-up image.

Martin Bean
and for IE it'll be something like this :-document.onkeypress = function (event) { if (event == undefined) { event = window.event; }if (event.keyCode == 27) { document.getElementById('something').display='none'; } }
developer
A: 

In addition else you close the window and only the div needs te be hidden. esc only works when image is showed (has display is block)

<script type="text/javascript">
    window.onkeyup = function (event) {
        if (event.keyCode == 27 && document.getElementById('blah blah').display='block') {
            document.getElementById('blah blah').display='none';
        }
    }
</script>
Tim