INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Opening and closing a window

How to close all open popup windows you opened by simonchristieis
Posted: 20 Jan 04 (Edited 29 Oct 04)

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:output 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:otherwise>
       <xsl:value-of select="@value"/>
      </xsl:otherwise>
     </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>


Back to Javascript FAQ Index
Back to Javascript Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close