0

JavaScript event onClick close window not firing after clicking and viewing PrettyPhoto image.

HTML

<button type="button" onClick="closeWin()">Close Window</button>

JavaScript

function closeWin() {
    window.close();
}

jQuery

$(document).ready(function(){
    $("a[rel^='prettyPhoto']").prettyPhoto({
        callback: function() {
            closeWin();
        }
    });
});
crashtestxxx
  • 1,224
  • 5
  • 19
  • 28

2 Answers2

2

Got another answer for closing window

window.open('','_self');
self.close();

Check this Fiddle

Works in Chrome, Safari.

In FF, you need to change the dom.allow_scripts_to_close_windows value to true

Ranganadh Paramkusam
  • 3,768
  • 2
  • 21
  • 32
1

You can close window by using window.close(); only by setting "off" security flags

In firefox, you can do this by going into about:config, click "I'll be careful, I promise" button and search for

dom.allow_scripts_to_close_windows

You'll see that it was set to false.

Make that true, you can close window by using window.close()

But this gives security issues.

There is another solution for closing the window, you can close the window which you opened.

Check that here: jsFiddle

Ranganadh Paramkusam
  • 3,768
  • 2
  • 21
  • 32