|
-
Sep 6th, 2008, 02:20 AM
#1
Thread Starter
Frenzied Member
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.
-
Sep 6th, 2008, 03:11 AM
#2
Thread Starter
Frenzied Member
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
-
Sep 7th, 2008, 10:37 AM
#3
Thread Starter
Frenzied Member
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);
}
-
Sep 8th, 2008, 12:00 AM
#4
Thread Starter
Frenzied Member
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.
-
Sep 8th, 2008, 10:52 PM
#5
Thread Starter
Frenzied Member
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.
-
Sep 8th, 2008, 10:52 PM
#6
Thread Starter
Frenzied Member
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.
-
Sep 9th, 2008, 12:41 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|