Search code examples
javascriptjquerylimit

How to open new tab only 1 time?


<script>
$(document).click(function() { 
    window.open("http://google.com", "_blank");
});
</script>

With above code, when I click anywhere, the tab will be opened. However, when I click more, the new tab will be opened. So, how to disable above code after click 1 time ?


Solution

  • Use jquery .one() http://api.jquery.com/one/

    <script>
    $(document).one("click",function() { window.open("http://google.com", "_blank");});
    </script>