crv
crv

Reputation: 31

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>

Upvotes: 1

Views: 7046

Answers (1)

Guffa
Guffa

Reputation: 700362

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.

Upvotes: 2

Related Questions