Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to close all open popup windows you opened

Opening and closing a window

How to close all open popup windows you opened

by  simonchristieis  Posted    (Edited  )
To avoid the situation arising, where you have multiple windows open but can't close them, because you dont know the names.

Stores the name in an array when you open the popups, and loop through the array to close all open windows.


Code:
document.activePopup = new Array;

function openWindow(sUrl,sName,sProps){
 document.activePopup.push(window.open(sUrl,sName,sProps))
}

function closePopup(){
for(var x=0;x<document.activePopup.length;x++)
 document.activePopup[x].close()
}

<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="Yahtzino.xsl" ?>

<yahtzino>

<player number="1" name="Simon" rolls="4" gameOver="F" currentTurn="T" score="123" colour="green">
<score code="s1" description="Ones" locked="F" value="0" bonusValue="4" setPoints=""/>
<score code="s2" description="Twos" locked="F" value="0" bonusValue="8" setPoints=""/>
<score code="s3" description="Threes" locked="F" value="0" bonusValue="12" setPoints=""/>
<score code="s4" description="Fours" locked="F" value="0" bonusValue="16" setPoints=""/>
<score code="s5" description="Fives" locked="F" value="0" bonusValue="20" setPoints=""/>
<score code="s6" description="Sixes" locked="F" value="0" bonusValue="24" setPoints=""/>

<score code="te" description="Bonus" locked="T" value="0" bonusValue="84" setPoints="100"/>
<score code="tt" description="Top Total" locked="T" value="0" bonusValue="84" setPoints="100"/>

<score code="m2" description="One Pair" locked="F" value="0"/>
<score code="m22" description="Two Pairs" locked="F" value="0"/>
<score code="m222" description="Three Pair" locked="F" value="0"/>

<score code="m3" description="Three of a kind" locked="F" value="0"/>
<score code="m4" description="Four of a kind" locked="F" value="0"/>
<score code="m5" description="Five of a kind" locked="F" value="0"/>

<score code="ml" description="Low Straight" locked="F" value="0"/>
<score code="mh" description="High Straight" locked="F" value="0"/>
<score code="mf" description="Full Straight" locked="F" value="0"/>

<score code="mhu" description="Hut" locked="F" value="0"/>
<score code="mho" description="House" locked="F" value="0"/>
<score code="mt" description="Tower" locked="F" value="0"/>

<score code="mc1" description="First Chance" locked="F" value="0"/>
<score code="mc2" description="Last Chance" locked="F" value="0"/>

<score code="my1" description="Yahtzino" locked="F" value="0" setPoints="100"/>
<score code="my2" description="Yahtzingo" locked="F" value="0" setPoints="300"/>

<score code="tt1" description="Top Total" locked="T" value="0"/>
<score code="tb" description="Bottom Total" locked="T" value="0"/>
<score code="tf" description="Final Total" locked="T" value="0"/>
</player>

<player number="2" name="Sarah" rolls="17" gameOver="F" currentTurn="T" score="546" colour="yellow">
<score code="s1" description="Ones" locked="F" value="0" bonusValue="4" setPoints=""/>
<score code="s2" description="Twos" locked="F" value="0" bonusValue="8" setPoints=""/>
<score code="s3" description="Threes" locked="F" value="0" bonusValue="12" setPoints=""/>
<score code="s4" description="Fours" locked="F" value="0" bonusValue="16" setPoints=""/>
<score code="s5" description="Fives" locked="F" value="0" bonusValue="20" setPoints=""/>
<score code="s6" description="Sixes" locked="F" value="0" bonusValue="24" setPoints=""/>

<score code="te" description="Bonus" locked="T" value="0" bonusValue="84" setPoints="100"/>
<score code="tt" description="Top Total" locked="T" value="0" bonusValue="84" setPoints="100"/>

<score code="m2" description="One Pair" locked="F" value="0"/>
<score code="m22" description="Two Pairs" locked="F" value="0"/>
<score code="m222" description="Three Pair" locked="F" value="0"/>

<score code="m3" description="Three of a kind" locked="F" value="0"/>
<score code="m4" description="Four of a kind" locked="F" value="0"/>
<score code="m5" description="Five of a kind" locked="F" value="0"/>

<score code="ml" description="Low Straight" locked="F" value="0"/>
<score code="mh" description="High Straight" locked="F" value="0"/>
<score code="mf" description="Full Straight" locked="F" value="0"/>

<score code="mhu" description="Hut" locked="F" value="0"/>
<score code="mho" description="House" locked="F" value="0"/>
<score code="mt" description="Tower" locked="F" value="0"/>

<score code="mc1" description="First Chance" locked="F" value="0"/>
<score code="mc2" description="Last Chance" locked="F" value="0"/>

<score code="my1" description="Yahtzino" locked="F" value="0" setPoints="100"/>
<score code="my2" description="Yahtzingo" locked="F" value="0" setPoints="300"/>

<score code="tt1" description="Top Total" locked="T" value="0"/>
<score code="tb" description="Bottom Total" locked="T" value="0"/>
<score code="tf" description="Final Total" locked="T" value="0"/>
</player>

<player number="3" name="Bob" rolls="1" gameOver="F" currentTurn="T" score="546" colour="blue">
<score code="s1" description="Ones" locked="F" value="0" bonusValue="4" setPoints=""/>
<score code="s2" description="Twos" locked="F" value="0" bonusValue="8" setPoints=""/>
<score code="s3" description="Threes" locked="F" value="0" bonusValue="12" setPoints=""/>
<score code="s4" description="Fours" locked="F" value="0" bonusValue="16" setPoints=""/>
<score code="s5" description="Fives" locked="F" value="0" bonusValue="20" setPoints=""/>
<score code="s6" description="Sixes" locked="F" value="0" bonusValue="24" setPoints=""/>

<score code="te" description="Bonus" locked="T" value="0" bonusValue="84" setPoints="100"/>
<score code="tt" description="Top Total" locked="T" value="0" bonusValue="84" setPoints="100"/>

<score code="m2" description="One Pair" locked="F" value="0"/>
<score code="m22" description="Two Pairs" locked="F" value="0"/>
<score code="m222" description="Three Pair" locked="F" value="0"/>

<score code="m3" description="Three of a kind" locked="F" value="0"/>
<score code="m4" description="Four of a kind" locked="F" value="0"/>
<score code="m5" description="Five of a kind" locked="F" value="0"/>

<score code="ml" description="Low Straight" locked="F" value="0"/>
<score code="mh" description="High Straight" locked="F" value="0"/>
<score code="mf" description="Full Straight" locked="F" value="0"/>

<score code="mhu" description="Hut" locked="F" value="0"/>
<score code="mho" description="House" locked="F" value="0"/>
<score code="mt" description="Tower" locked="F" value="0"/>

<score code="mc1" description="First Chance" locked="F" value="0"/>
<score code="mc2" description="Last Chance" locked="F" value="0"/>

<score code="my1" description="Yahtzino" locked="F" value="0" setPoints="100"/>
<score code="my2" description="Yahtzingo" locked="F" value="0" setPoints="300"/>

<score code="tt1" description="Top Total" locked="T" value="0"/>
<score code="tb" description="Bottom Total" locked="T" value="0"/>
<score code="tf" description="Final Total" locked="T" value="0"/>
</player>

<player number="4" name="Harry" rolls="12" gameOver="F" currentTurn="T" score="546" colour="red">
<score code="s1" description="Ones" locked="F" value="4" bonusValue="4" setPoints=""/>
<score code="s2" description="Twos" locked="F" value="8" bonusValue="8" setPoints=""/>
<score code="s3" description="Threes" locked="F" value="12" bonusValue="12" setPoints=""/>
<score code="s4" description="Fours" locked="F" value="16" bonusValue="16" setPoints=""/>
<score code="s5" description="Fives" locked="F" value="20" bonusValue="20" setPoints=""/>
<score code="s6" description="Sixes" locked="F" value="24" bonusValue="24" setPoints=""/>

<score code="te" description="Bonus" locked="T" value="0" bonusValue="84" setPoints="100"/>
<score code="tt" description="Top Total" locked="T" value="0" bonusValue="84" setPoints="100"/>

<score code="m2" description="One Pair" locked="F" value="0"/>
<score code="m22" description="Two Pairs" locked="F" value="0"/>
<score code="m222" description="Three Pair" locked="F" value="0"/>

<score code="m3" description="Three of a kind" locked="F" value="0"/>
<score code="m4" description="Four of a kind" locked="F" value="0"/>
<score code="m5" description="Five of a kind" locked="F" value="0"/>

<score code="ml" description="Low Straight" locked="F" value="0"/>
<score code="mh" description="High Straight" locked="F" value="0"/>
<score code="mf" description="Full Straight" locked="F" value="0"/>

<score code="mhu" description="Hut" locked="F" value="0"/>
<score code="mho" description="House" locked="F" value="0"/>
<score code="mt" description="Tower" locked="F" value="0"/>

<score code="mc1" description="First Chance" locked="F" value="0"/>
<score code="mc2" description="Last Chance" locked="F" value="0"/>

<score code="my1" description="Yahtzino" locked="F" value="0" setPoints="100"/>
<score code="my2" description="Yahtzingo" locked="F" value="0" setPoints="300"/>

<score code="tt1" description="Top Total" locked="T" value="0"/>
<score code="tb" description="Bottom Total" locked="T" value="0"/>
<score code="tf" description="Final Total" locked="T" value="0"/>
</player>

<gameData playerCount="4">
<dice number="1" value="" hold="F"/>
<dice number="2" value="" hold="F"/>
<dice number="3" value="" hold="F"/>
<dice number="4" value="" hold="F"/>
<dice number="5" value="" hold="F"/>
<dice number="6" value="" hold="F"/>
<playerOrder number="1" nextTurn="1"/>
<playerOrder number="2" nextTurn="1"/>
<playerOrder number="3" nextTurn="1"/>
<playerOrder number="4" nextTurn="-3"/>
<currentPlayer Name="Sarah" number="2" addedRolls="3"/>
</gameData>



</yahtzino>




<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:v="urn:schemas-microsoft-com:vml">

<xsl:import href="GameData.xsl" />
<xsl:eek:utput method="xml" omit-xml-declaration="yes"/>

<xsl:template match="/">
<xsl:call-template name="ScreenBase"/>
</xsl:template>

<xsl:template name="ScreenBase">
<html id="htmlall">
<head>
<title>
Yahtzino - Fun for all the stoneheads
</title>
<style>
v\:* { behavior: url(#default#VML); }
</style>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<script type="text/javascript" language="javascript" src="Yahtzino.js"></script>
</head>
<body ondrag="javascript:return false;">
<xml id="GameData"><xsl:copy-of select="."/></xml>
<xsl:call-template name="ScreenBody"/>
</body>
</html>
</xsl:template>

<xsl:template name="ScreenBody">
<table id="GameDetails">
<xsl:call-template name="PlayerDetails">
<xsl:with-param name="playerName" select="yahtzino/gameData/currentPlayer/@Name" />
</xsl:call-template>
</table>
</xsl:template>

</xsl:stylesheet>



function changePlayer()
{
addRolls()
var oCurrPlayer = GameData.documentElement.selectSingleNode("/yahtzino/gameData/currentPlayer");

var oNextCalc = GameData.documentElement.selectSingleNode(
"/yahtzino/gameData/playerOrder[@number = "+ oCurrPlayer.getAttribute('number') +"]");

var oNextPlayer = GameData.documentElement.selectSingleNode(
"/yahtzino/player[@number = '"+ eval(parseInt(oCurrPlayer.getAttribute('number')) + parseInt(oNextCalc.getAttribute("nextTurn"))) +"']");

oCurrPlayer.setAttribute("Name", oNextPlayer.getAttribute('name'))
oCurrPlayer.setAttribute("number", oNextPlayer.getAttribute('number'))
renderGameData()
}

function renderGameData()
{
var oXSL = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
var sTransformedXML = ';

oXSL.async = false;
oXSL.load("GameData.xsl");

sTransformedXML = GameData.transformNode(oXSL);

GameDetails.outerHTML = sTransformedXML;
}

function addRolls()
{
var oCurrPlayer = GameData.documentElement.selectSingleNode("/yahtzino/gameData/currentPlayer");
var oPlayer = GameData.documentElement.selectSingleNode(
"/yahtzino/player[@number = '"+ oCurrPlayer.getAttribute('number') +"']");
oPlayer.setAttribute("rolls", parseInt(oCurrPlayer.getAttribute('addedRolls')) + parseInt(oPlayer.getAttribute('rolls')))
}

function removeRolls()
{
var oCurrPlayer = GameData.documentElement.selectSingleNode("/yahtzino/gameData/currentPlayer");
var oPlayer = GameData.documentElement.selectSingleNode(
"/yahtzino/player[@number = '"+ oCurrPlayer.getAttribute('number') +"']");
oPlayer.setAttribute("rolls", parseInt(oPlayer.getAttribute('rolls')) - 1)
}

function testHarness(x)
{
changePlayer()
}




<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:v="urn:schemas-microsoft-com:vml">

<xsl:template match="/">
<table id="GameDetails">
<xsl:call-template name="PlayerDetails">
<xsl:with-param name="playerName" select="yahtzino/gameData/currentPlayer/@Name" />
</xsl:call-template>
</table>
</xsl:template>

<xsl:template match="score">
<tr>
<td>
<xsl:if test="@locked = 'F'">
<xsl:attribute name="onClick">javascript:testHarness('<xsl:value-of select="@description"/>')</xsl:attribute>
<xsl:attribute name="onMouseOver">this.style.cursor = 'hand'</xsl:attribute>
</xsl:if>
<xsl:value-of select="@description"/>
</td>
<td>
<xsl:if test="@locked = 'F'">
<xsl:attribute name="onClick">alert("Hello")</xsl:attribute>
<xsl:attribute name="onMouseOver">this.style.cursor = 'hand'</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="@code = 'te'">
<xsl:if test="sum(../score[contains(@code,'s')]/@value) >= @bonusValue">
<xsl:value-of select="@setPoints"/>
</xsl:if>
</xsl:when>
<xsl:when test="contains(@code,'tt')">
<xsl:if test="sum(../score[contains(@code,'s')]/@value) >= ../score[contains(@code,'te')]/@bonusValue">
<xsl:value-of select="sum(../score[contains(@code,'s')]/@value) + ../score[contains(@code,'te')]/@setPoints"/>
</xsl:if>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="@value"/>
</xsl:eek:therwise>
</xsl:choose>


</td>
</tr>
</xsl:template>


<xsl:template name="PlayerDetails">
<xsl:param name="playerName"/>
<tr>
<td>Name</td><td><xsl:value-of select="$playerName"/></td>
<td rowspan="28" valign="bottom"><v:rect title='Rolls: {/yahtzino/player[@name = $playerName]/@rolls}' style='width:10pt;height:{/yahtzino/player[@name = $playerName]/@rolls * 10}pt' fillcolor="{/yahtzino/player[@name = $playerName]/@colour}"></v:rect>
</td>
</tr>
<xsl:apply-templates select="/yahtzino/player[@name = $playerName]/score"/>
</xsl:template>

</xsl:stylesheet>

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top