$(".close-btn").on("click", function () { var userAgent = navigator.userAgent; if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") != -1) { window.open("", "_self").close(); } else { window.opener = null; window.open("", "_self"); window.close(); } });