Search code examples
javascriptjquerybuttonclickjquery-callbackprettyphoto

JavaScript window.close not firing after clicked on PrettyPhoto


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();
        }
    });
});

Solution

  • 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