4

This is my js code to prevent multiple tab in same browser.

<script type="text/javascript">
        window.onload = function(){
        if (document.cookie.indexOf("_instance=true") === -1) {
        document.cookie = "_instance=true";
        // Set the onunload function
        window.onunload = function(){
            document.cookie ="_instance=true;expires=Thu, 01-Jan-1970 00:00:01 GMT";
        };
        // Load the application
        }
        else {
             alert(" Security Alerts.You Are Opening Multiple Window. This window will now close.");
             var win = window.open("about:blank", "_self"); win.close();
        // Notify the user
        }
        };
</script>

It is work fine in chrome and firefox But It always make alert in Safari Browser(Mac). Is there any other replace code for that. Thanks in advance.

Sankar Smith
  • 338
  • 1
  • 5
  • 14
  • Not very sure, but may be you can try using sessionStorage instead of cookies, if document.cookie has compatibility issues in latest browsers. – Mohit Bhardwaj Dec 27 '16 at 10:08
  • [link](http://stackoverflow.com/a/32760401/6839761) It works fine in safari and other browsers. Thanks to Stackoverflow users. – Sankar Smith Dec 28 '16 at 11:06

0 Answers0