PDA

View Full Version : 2 windows communicating



Rohan72
03-26-2006, 07:56 PM
For a sportsteam, i'm trying to make an "interactive" scoreboard for use with a beamer. It was pretty easy to write when i put it all in 1 window (the scoreboard and the controls). But now i need to split it up so the scoreboard itself is displayed fullscreen and passed thru the beamer and the controls are on another window and seen only on the laptop screen.
what (javascript of html)-commands do i need to use to change the info on the scoreboard when a button is pressed on the control panel?

jscheuer1
03-26-2006, 08:34 PM
What's a beamer?

Rohan72
03-26-2006, 08:40 PM
oops, sorry... i meant a projector
here we usually call it a beamer...

jscheuer1
03-26-2006, 09:33 PM
I'm unfamiliar with that kind of setup but, if, on the lap top, the two windows are both going to be visible and the beamer is like an additional monitor showing only one of the two windows with the other window there but, off of its visible screen then here's what you do:

Have your control page open the scores page:


<input type="button" value="Open Scores Window" onclick="beamer=window.open('scores.htm');"><br>

where scores.htm is the name of the page with the scores on it.

Then, from the control page any variable on the scores page is now known as:


beamer.variableName

So, let's say you have a variable on the scores page called team1, you can change its value using javascript by:


beamer.team1='Red Sox'

from the control page.

You can also change the value of a text input, the innerHTML of an element or even run a function that is on or available to the scores page from the control page simply by prefacing the normal code with beamer. examples:


<input type="button" onclick="beamer.document.getElementById('team1').value='Red Sox'">

on the control page will change the displayed value of:


<input id="team1" type="text" value="Phillies">

on the scores page and:


<input type="button" onclick="beamer.alert('Red Sox')">

on the control page will cause an alert on the scores page.

etc.

Rohan72
03-26-2006, 09:48 PM
thanx a lot!

i'm gonna give it a try. it'll take a while before it's finished, but when it's done, i'll post the result here.

Rohan72
03-28-2006, 09:58 PM
Not working :(

Is anyone interested in taking a look at the script?

(its pretty long, so I'll need to send it)

jscheuer1
03-29-2006, 07:06 AM
Well, I tested out my advice before posting it. However, it is just a general outline of the principals involved. One thing I didn't mention is that say you are activating a function on the scores page from the control page and you need to pass it an element from the scores page as well, both must be prefaced with the scores page variable that was created when you opened it.

Enough theory, you can archive your two pages as a .zip and attach them to a post here. Use the advanced editor and scroll down below it to the "Manage attachments" area. Once you've uploaded it, use the editors 'Attachments' drop down to insert it into the message.

Or better yet, set up a demo of your two pages live on the web and include the URL to the control page in a message.

Rohan72
03-29-2006, 02:14 PM
Here is the code (in zip). Open the index file (is also the controlpanel, and there is a button to open the scoreboard itself. The scoreboard runs on fullscreen.
Can someone look at it and help me out with the errors?

jscheuer1
03-29-2006, 04:10 PM
First problem is that you cannot setnames() onload of the control page because the scores page isn't open yet:


<BODY onLoad="setnames()" bgcolor="#ffffff" text="#000000">

Get rid of the red part.

Your setnames() function appears valid and will work after the scores page is loaded if setnames() is the only function on the control page. But, there must be a syntax error in one of the previous functions, this invalidates all code that follows. Here it is (at or around line#57 on the control page):


if scores.(board.A11points.value!=0){scores.board.A11points.value--;scores.board.AScore.value--;}}

should be:


if (scores.board.A11points.value!=0){scores.board.A11points.value--;scores.board.AScore.value--;}}

There could be other problems but, you seem to have grasped the fundamentals, and this should get you on your way. At least setnames() will now work.

Since you will be testing and presumably using this locally as opposed to on the web, adding this line (in red):


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- saved from url=(0014)about:internet -->

to both pages, will prevent the local security warning.

Twey
03-29-2006, 04:12 PM
What exactly is this "security warning" meant to do? Any writer of a malicious HTML page just has to add above line to disable it.

jscheuer1
03-29-2006, 04:25 PM
What exactly is this "security warning" meant to do? Any writer of a malicious HTML page just has to add above line to disable it.

You've got me there. Or rather Microsoft there. I guess it was assumed that this (Microsoft's) scheme will not prevent all abuses, simply cut down on them. Except, with more than the average restrictions settings, IE will not allow the code to run even with this 'Mark of the Web' thing.

Rohan72
03-29-2006, 04:58 PM
Thanx a lot !!! It works !!!

I encountered some more errors (score. forgotten), but i corrected them.

All i got to do now is add some gfx and sponsors on it and its ready for use.


update : i'm gonna leave the security warning on the scoreboard itself. with the code you gave me, it shows the titlebar and it needs to run on fullscreen.
but thanks for it anyway, i can use it in some other projects :)