SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript open new popup window with 5 second time delay

    hi everyone.

    i need to delay a page from opening a new window for a minimum of 5 seconds to allow some php processing (inserting a new record into a table) to occur first. the open window code works fine without the time delay, but as soon as i attempt to put a delay in, nothing happens eg, the page no longer opens a new window called newrecord.php. i'd appreciate some help. thx.

    a submit button calls the function like so:
    <input type="submit" name="AddRecord" id="AddRecord" value="Add New Record" onClick="confirmCreateNewRecord()" />


    Code:
    <SCRIPT LANGUAGE="JavaScript">
    	function confirmCreateNewRecord()
    	{
    		var isConfirmed=confirm('Are you sure you wish to create a new  record now? This action cannot be undone or cancelled.')
    		if(isConfirmed)
    		{
    			window.setTimeout('redirectUser()',5000);
    		}
    	}
    	function redirectUser()
    	{  		
    		window.open("newrecord.php?ID=<?php echo $ID ?>","_blank","toolbar=no, location=yes, status=no, menubar=no, scrollbars=yes, resizable=yes, width=800, height=550");
    	}   
    </SCRIPT>

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Location
    Bs. As. - Argentina
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    May be a popup blocker problem.

    When the function fires the "redirectUser()" without the delay it work because it's in the same "event scope" that it happens, so, the browsers "thinks" "ok, this popup is what the user want to see".

    Instead, when you put it into a "setTimeout()" the call is being generated from the JavaScript engine, so, the browser "thinks" "what is that? who is telling me to open a new window? may be an ad, i will discard this call" or similar

    So, check your popup blocker rules to see if this is what is happening.


    See you

  3. #3
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply.

    I really got frustrated with why the time delay didn't work, so instead, i just called a php routine with the 'sleep' method then used a header redirect. that seemed to give me what i needed. plus it avoided javascript!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •