Dave,
Yes you can access other frames from a Java script, but I think you have to
be in the parent or one of the child frames to do it. Here is a sample JS
from my book accessing frames for a tic-tac-toe game.
I recall reading a security bulliten a while ago where there was a bug in IE
and hackers could access frames from unrelated windows. I think this has
been fixed, but of course it depends on your version of IE and what patches
you have.
Troy Sosamon
--------------
function isBlank(n) {
if(owns("player",n) || owns("computer",n)) return false
return true
}
function owns(who,i) {
var fr = parent.parent.frames[1]
var doc = fr.document
var field = doc.forms[0].elements[i]
if(field==null || field.value==who) return true
else return false
}
function setOwner(who,n) {
var fr = parent.parent.frames[1]
var doc = fr.document
var field = doc.forms[0].elements[n]
field.value=who
}
function ticTacToe(who,n1,n2,n3) {
if(owns(who,n1) && owns(who,n2) && owns(who,n3)) {
parent.parent.frames[3].focus()
return true
}
return false
}
function isTicTacToe(who) {
if(ticTacToe(who,0,1,2)) return true
if(ticTacToe(who,3,4,5)) return true
if(ticTacToe(who,6,7,8)) return true
if(ticTacToe(who,0,3,6)) return true
if(ticTacToe(who,1,4,7)) return true
if(ticTacToe(who,2,5,8)) return true
if(ticTacToe(who,0,4,8)) return true
if(ticTacToe(who,2,4,6)) return true
return false
}
function gameOver() {
numMoves = 0
for(i=0;i<9;++i) {
if(!isBlank(i)) ++numMoves
}
if(numMoves==9) return true
if(isTicTacToe("player")) return true
if(isTicTacToe("computer")) return true
return false
}
function computerMoves() {
if(gameOver()) return -1
var newMove = Math.round(9*Math.random())
while(!isBlank(newMove)) {
newMove = (newMove + 1) % 9
}
setOwner("computer",newMove)
return newMove
}
function playerMoves() {
if(!gameOver() && isBlank(cell)) {
setOwner("player",cell)
var move = computerMoves()
location.href="o.htm"
if(move!=-1) parent.frames[move].location.href="x.htm"
}
}
function showWinner() {
if(isTicTacToe("player")) alert("Congratulations! You win.")
}
function showLoser() {
if(isTicTacToe("computer")) alert("Sorry. You Lose.")
}
===== Original Message from [EMAIL PROTECTED] at 6/24/02 10:26 am
>Is it possible to read the entire contents of one frame from within another
>frame? Something like:
> var txt = parent.otherFrame.document.innerHTML;
>
>I have my doubts as this would open a huge security hole, but I thought I'd
>ask anyway.
>
>Dave Shelley
>
>________________________________________________________________________
>TO UNSUBSCRIBE: send a plain text/US ASCII email to [EMAIL PROTECTED]
> with unsubscribe witango-talk in the message body
________________________________________________________________________
TO UNSUBSCRIBE: send a plain text/US ASCII email to [EMAIL PROTECTED]
with unsubscribe witango-talk in the message body