简体   繁体   中英

Open Popup after 5 seconds what am I doing wrong?

I placed a popup on page load, but I would prefer to appear after 5 seconds. I inserted tie out code, but it is not working what am I doing wrong?

<script type="text/javascript">

        var link;
        var element;
                    t=setTimeout(openpopupFunction,5000);
        function openPopUp(url)
        {
            link = url;
            element = document.getElementById("background");
            element.style.display = "block";
            element = document.getElementById("popup");
            element.style.display = "block";

        }
</script>

You are using a different function name when you try to call it. Use:

var t = setTimeout(openPopUp, 5000);

You only need the variable t here if you need to stop the timeout.

Side note: You would normally declare the variables link and element inside the function so that they are local, not global variables. Try to keep as little as possible in the global scope, to minimise the risk of conflicts between scripts and with other things that are already in the global scope.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM