Javascript open/close windows

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Javascript open/close windows

Post by Epiales »

Okay, so I have some code I've jumbled together to get a popup window open for my arena. What I can't figure out is how to close that window and open another window when they click ENTER to go into the arena. Here is the code I currently have if you can figure me out lol...

php code:

Code: Select all

<div><center><a href="#" onclick="popup('popUpDiv')"><img src='images/arena.png' width="150" height="150"></center></a>
<script type="text/javascript" src="popup.js"></script>

    <div id="blanket" style="display:none;"></div>
    
      <a href="#" onClick="popup('popUpDiv')"><center><img src='images/arenatitle.png'></center></a>

    <div id="popUpDiv" style="display:none;">
    
 <div id="closeimg"> <a href="#" onClick="popup('popUpDiv')" ><img src='images/close3.png' width="40" height="40" style="margin-bottom:17px"></a>    </div>
  
 <div id="arenaheader"><img src='images/arena.png' width="40" height="40" style="vertical-align:middle">ARENA<img src='images/arena.png' width="40" height="40" style="vertical-align:middle"></div>
 <div id="arenawrapper"> 

<div id="arenapve">
    <div id="arenabarcolor">PVE</div>
    <p>Battle NPC's to earn experience and money!</p>
        
    
    
<div id="arenadiventerenter">

<input type="submit" value="Enter" />
</div>

<div id="arenadivshop" style="float:right">
<input type="submit" value="Arena Shop" />
</div>

</div>

<div id="arenapvp">
    <div id="arenabarcolor">PVP</div>
    <p>Battle other players and earn respect in the Arena</p>


<div id="arenadivpvpenter">
<input type="submit" value="Enter" />
</div>

</div>
</div>
Javascript JS:

Code: Select all

<script>
function toggle(div_id) {
    var el = document.getElementById(div_id);
    if ( el.style.display == 'none' ) {    el.style.display = 'block';}
    else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
    if (typeof window.innerWidth != 'undefined') {
        viewportheight = window.innerHeight;
    } else {
        viewportheight = document.documentElement.clientHeight;
    }
    if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
        blanket_height = viewportheight;
    } else {
        if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
            blanket_height = document.body.parentNode.clientHeight;
        } else {
            blanket_height = document.body.parentNode.scrollHeight;
        }
    }
    var blanket = document.getElementById('blanket');
    blanket.style.height = blanket_height + 'px';
    var popUpDiv = document.getElementById(popUpDivVar);
    popUpDiv_height=blanket_height/2-200;//200 is half popup's height
    popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerHeight;
    } else {
        viewportwidth = document.documentElement.clientHeight;
    }
    if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
        window_width = viewportwidth;
    } else {
        if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
            window_width = document.body.parentNode.clientWidth;
        } else {
            window_width = document.body.parentNode.scrollWidth;
        }
    }
    var popUpDiv = document.getElementById(popUpDivVar);
    window_width=window_width/2-200;//200 is half popup's width
    popUpDiv.style.left = window_width + 'px';
}
function popup(windowname) {
    blanket_size(windowname);
    window_pos(windowname);
    toggle('blanket');
    toggle(windowname);        
}
</script>
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Javascript open/close windows

Post by Epiales »

I have found other options YAY Thx :)
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Advanced Help and Support”