CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 1999
    Location
    North Germany
    Posts
    306

    Waiting till page is loaded

    I hope someone can help me with a small problem. I have a javascript which shall open some external links in a new window.

    My current problem is that the next link shall be only opened when the one before is loaded completely

    Code:
     
    my_window1 = window.open('http://​URL1...','_blank',"status,heigh​t=600,width=800");
     // -> wait till Window is loaded and then continue with the next line
    
    my_window2 = window.open('http://​URL2...','_blank',"status,heigh​t=600,width=800");
     // -> wait till Window is loaded  and then continue with the next line
    
    my_window3 = window.open('http://​URL3...','_blank',"status,heigh​t=600,width=800");
     // -> wait till Window is loaded  and then continue with the next line
    
    my_window4 = window.open('http://​URL4...','_blank',"status,heigh​t=600,width=800");
    How can I do this?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Waiting till page is loaded

    Use the onload event for the current window to load the next window.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jun 1999
    Location
    North Germany
    Posts
    306

    Re: Waiting till page is loaded

    I can't because the new called websites are external websites which I can't change. Is there a way that I can ask the new window if it's finished with loading and stop the script in the main page till then?

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Waiting till page is loaded

    Yes, you can. Being from a different domain has nothing to do with it.

    Code:
      var winGoogle = window.open("http://www.google.com","google","status,heigh​t=600,width=800");
      winGoogle.onload = function () {
        alert("All done!");
      }
    Last edited by PeejAvery; June 8th, 2012 at 05:31 PM. Reason: Fixed spelling
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jun 1999
    Location
    North Germany
    Posts
    306

    Re: Waiting till page is loaded

    Hey cool thank you :-)

  6. #6
    Join Date
    Jun 1999
    Location
    North Germany
    Posts
    306

    Re: Waiting till page is loaded

    Ok I tried this but it's opening only one page which won't be closed automatic. What is wrong? I would have expected this: Opening window 1, closing it when it's finished with loading and then opening the next one and so on
    Code:
    <script type="text/javascript">
    my_window0 = window.open('https://url1....','_blank',"status,height=600,width=800");
    my_window0.onload = function () 
    { 
     	my_window0.close (); 
    	my_window1 = window.open('https://url2....','_blank',"status,height=600,width=800");
    	my_window1.onload = function () 
    	{ 
     		my_window1.close (); 
    		my_window2 = window.open('https://url3....','_blank',"status,height=600,width=800");
    		my_window2.onload = function () 
    		{ 
     			my_window2.close (); 
    		}
    	}
    }
    </script><br>

  7. #7
    Join Date
    May 2002
    Posts
    10,943

    Re: Waiting till page is loaded

    Since you're dealing with separate domains, some browsers will block it due to cross-domain script issues. There's nothing around that unless you control the browser usage.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured