LearneR
LearneR

Reputation: 47

I need to close a pop-up window after some period of time

I need to close the pop-window which is triggered from 3rd party site after some time passes.
I know we can close the pop-up using setTimeout("self.close()",5000) in body of the page, but the pop-up is triggering from other server.

Upvotes: 1

Views: 3476

Answers (3)

Vishal
Vishal

Reputation: 11

Check this out.

<script type="text/javascript">
    var pop;
    function cl() {
        form1.elements["wt"].value=65;
        pop.close();
    }

    function open_win() 
    {
        pop = window.open("loading_page.html",'popUpWindow','height=200,width=150,left=10,top=10,resizable=yes,position=center,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes',align="center"); 
        setTimeout("cl()",5000);
    }
</script>

I used the cl() to populate a textfield after 5 seconds having form name as form1 and textfield name as wt.

Upvotes: 1

Simon
Simon

Reputation: 2830

I don't think you can control windows that are opened from a different session. Pretty sure that would be a big security hole if you could.

Upvotes: 1

Quentin
Quentin

Reputation: 943563

Just call the close method of the new window.

function() { // It is a popup, so obviously you need to call this from a user triggered event and not page load
    var pop = window.open('http://example.com');
    var close = function() {
        pop.close();
    };
    setTimeout(close, 2000);
}

Upvotes: 0

Related Questions