Results 1 to 7 of 7

Thread: Controlling second window from first (changing location periodically)

  1. #1

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Controlling second window from first (changing location periodically)

    what i want to do is control a second browser window from the first by loading a new page in it every 10 seconds. which page to load will be figured out by php from my database.

    my javascript sucks..can someone help me make this "pseudo code" work?
    Code:
    function start() {
      //get name for page we want to show
      var _page = <?php echo(get_page()); ?>;
      //open new page if first run, or use existing if allready done that
      if(!_window)
        var _window=window.open('_page , '', 'width=200,height=200');
      setTimeout(function(){show(_page,_window); }, 10000);
    
    }
    
    funtion show(_page,_window) {
      //set  the page displayed in the second window
      _window.location=_page;
      //start over
      start();
    }

    the above code will run in from my page. Idea is you click a button. It then open a new browser window, and load a certain page in there (window.location). Then wait 10 seconds, get the name of the next page and reuse the same browser window to display that one.
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  2. #2

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Controlling second window from first (changing location periodically)

    Code:
    <?php
    
    	echo "<script>var newWindow=window.open('testpage1.html', 'TestWindow 1', 'width=200,height=200');</script>";
    	
    	sleep(10);
    	
    	echo "<script>newWindow.close();</script>";
    
    ?>
    ...alternative idea...dont work...not sleeping
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  3. #3

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Controlling second window from first (changing location periodically)

    anything icky about this code i got online?
    Code:
    <script type="text/javascript">
    var SlideWindow;
    function SlideShow()
    {
      SlideWindow = open("Slide1.jpg", "", "width=300,height=200");
      SlideWindow.moveTo(400,400);
      setTimeout("SlideWindow.location='Slide2.jpg'", 2000);
      setTimeout("SlideWindow.location='Slide3.jpg'", 4000);
      setTimeout("SlideWindow.location='Slide4.jpg'", 6000);
      setTimeout("SlideWindow.location='Slide5.jpg'", 8000);
      setTimeout("SlideWindow.close()", 10000);
    }
    </script>
    <input type="button" value="Slide Show" onclick="SlideShow()"/>
    reason i ask is that if i replace the jpg's with url's like "http://www.google.com", etc it stop working as it should. The time intervals seems wrong,some pages get skipped, shows in wrong order (all this problems occur randomly....i cannot find a trend)
    Check this page to see what I am talking about.
    I do this:
    Code:
    var SlideWindow2;
    function SlideShow2()
    {
      SlideWindow2 = open("http://www.google.com", "", "width=300,height=200");
      SlideWindow2.moveTo(400,400);
      setTimeout("SlideWindow2.location='http://www.yahoo.com'", 2000);
      setTimeout("SlideWindow2.location='http://www.studypath.cn'", 4000);
      setTimeout("SlideWindow2.location='http://www.yandex.ru'", 6000);
      setTimeout("SlideWindow2.location='http://www.msn.com'", 8000);
      setTimeout("SlideWindow2.close()", 10000);
    }
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  4. #4

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Controlling second window from first (changing location periodically)

    The following work perfectly fine, with one big problem.
    Although a call to get_random_link() (php) returns a random url stored in the database, the javascript seems to reuse the first url returned by the call.

    Code:
    <script type="text/javascript">
    
    	var SlideWindow;
    	var _page;
    	function SlideShow() {
    		SlideWindow = open("http://www.mysite.com", "", "width=300,height=200");
    		SlideWindow.moveTo(600,600);
    		setInterval("new_page()", 4000);
    	}
    	
    	function new_page() {
    		SlideWindow.location="<?php echo($links->get_random_link()); ?>";
    	 }
    	 
    </script>
    Last edited by StrangerInBeijing; Oct 27th, 2008 at 04:14 AM.
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  5. #5

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Controlling second window from first (changing location periodically)

    oh my gawd, how could I not think. PHP = ServerSide, JavaScript ClientSide. the php will not be re-evaluated.
    aiya..can one be so dumb. i'll try some ajax solution.
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  6. #6

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Controlling second window from first (changing location periodically)

    oh my gawd, how could I not think. PHP = ServerSide, JavaScript ClientSide. the php will not be re-evaluated.
    aiya..can one be so dumb. i'll try some ajax solution.
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Controlling second window from first (changing location periodically)

    Thanks for talking to yourself, but you are going down the right path. If you know which URLs you need beforehand, write them out as a javascript array then loop through it. Else you'll need to make an XMLHttpRequest call everytime you need a new URL.

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