www.webdeveloper.com
Results 1 to 5 of 5

Thread: window function not working fully in chrome

  1. #1
    Join Date
    Feb 2007
    Posts
    13

    window function not working fully in chrome

    Hi,

    I have a small script that tries to open a child window. if successful, it then closes the child window and redirects the parent window. If this process fails, there is no child window, no redirection.

    the script below works fine in FireFox but in Chrome, if the process fails, the redirection still happens. I'm new to JS would appreciate your help

    many thanks

    Code:
    <script type="text/javascript">
    function openwindow(){
    	testWindow = window.open("popup.php","interaction","resizable=0,width=300,height=100,status=0");
    	setTimeout(function() { testWindow.close(); },1000);
    	setTimeout(function() { window.location = "http://www.google.com"; },1000);
    }
    </script>

  2. #2
    Join Date
    Feb 2011
    Posts
    25
    What do you define as a failure - not opening the window, not loading the document or an error in the loaded document?
    Nothing in your code is monitoring for any error, and there is nothing to prevent redirection after the timed period.
    In my tests both browsers behave as expected.

  3. #3
    Join Date
    Feb 2007
    Posts
    13
    apologies for being vague.

    Basically I want ALL action to STOP if testWindow is NOT created. This works as expected in FF but in chrome window.location still happens even if testWindow is null. I've changed the example to highlight. If I try the following in chrome, with "do not allow pop-ups" enabled the pop-up is prevented, but the re-direct still happens, rather than the alert, making it look as if chrome is misinterpreting the if statement. (I've tried variants such as swapping if and else, testWindow !== null, etc, all appear to produce the same results

    Code:
    <script type="text/javascript">
    function openwindow(){
      var testWindow = false;
      testWindow = window.open("popup.php","interaction","resizable=0,width=300,height=100,status=0");
      if(testWindow){
        setTimeout(function(){ 
          testWindow.close();
          window.location="http://www.google.com/"; }, 1000);
      }
      else{
        alert('testWindow was not created');
      }
    }
    </script>

  4. #4
    Join Date
    Feb 2011
    Posts
    25
    Quote Originally Posted by _giles_ View Post
    Basically I want ALL action to STOP if testWindow is NOT created.
    I presume we are talking about automatic popups here rather than user-requested, in which case you can assume they'll be blocked.
    I don't know if there's a spec for this but not all browsers return null.

  5. #5
    Join Date
    Feb 2007
    Posts
    13
    Quote Originally Posted by Calvert Tripesi View Post
    I presume we are talking about automatic popups here rather than user-requested
    Sorry - I'm still new to client side. Are you saying there's an explicit way to tell a browser that it's a user requested pop-up.
    Last edited by _giles_; 02-28-2011 at 11:25 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles