Forum Moderators: open

Message Too Old, No Replies

Two javascript actions in one click

little things you hide and little things you show.

         

The_Hat

7:08 pm on Jun 30, 2006 (gmt 0)

10+ Year Member



Here is what I am trying to do... I have some games on one of my sites and so I am trying to create a "boss button" on those pages that would popup a cover for whomever is using the game..

The problem is however the game is in javascript and so it pops right through the cover.. What I have done is found a script that would allow me to hide the div the game is in.. So right now I have two separate links... one to show the cover and one to hide the div the game is in.. Here's some code..

<script language=javascript type='text/javascript'>
function hidediv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('hideShow').style.visibility = 'hidden';
}
else {
if (document.layers) { // Netscape 4
document.hideShow.visibility = 'hidden';
}
else { // IE 4
document.all.hideShow.style.visibility = 'hidden';
}
}
}

function showdiv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('hideShow').style.visibility = 'visible';
}
else {
if (document.layers) { // Netscape 4
document.hideShow.visibility = 'visible';
}
else { // IE 4
document.all.hideShow.style.visibility = 'visible';
}
}
}
</script>

<script type="text/javascript">

var ie=document.all
var ns6=document.getElementById&&!document.all

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat" &&!window.opera)? document.documentElement : document.body
}

function enlarge(which, e, position, imgwidth, imgheight){
if (ie¦¦ns6){
crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage
if (position=="center"){
pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
horzpos=ns6? pageXOffset+window.innerWidth/2-imgwidth/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2
vertpos=ns6? pgyoffset+window.innerHeight/2-imgheight/2 : pgyoffset+ietruebody().clientHeight/2-imgheight/2
if (window.opera && window.innerHeight) //compensate for Opera toolbar
vertpos=pgyoffset+window.innerHeight/2-imgheight/2
vertpos=Math.max(pgyoffset, vertpos)
}
else{
var horzpos=ns6? pageXOffset+e.clientX : ietruebody().scrollLeft+event.clientX
var vertpos=ns6? pageYOffset+e.clientY : ietruebody().scrollTop+event.clientY
}
crossobj.style.left=horzpos+"px"
crossobj.style.top=vertpos+"px"

crossobj.innerHTML='<div class="topbar" align="right" id="dragbar"><span id="closetext" onClick="closepreview()"><img src="/images/bossscreentest3.gif" width="20" height="20" border="0"></span> </div><img src="'+which+'">'
crossobj.style.visibility="visible"
return false
}
else //if NOT IE 4+ or NS 6+, simply display image in full browser window
return true
}

function closepreview(){
crossobj.style.visibility="hidden"
}

function drag_drop(e){
if (ie&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx+"px"
crossobj.style.top=tempy+event.clientY-offsety+"px"
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
}
return false
}

function initializedrag(e){
if (ie&&event.srcElement.id=="dragbar"¦¦ns6&&e.target.id=="dragbar"){
offsetx=ie? event.clientX : e.clientX
offsety=ie? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}

document.onmousedown=initializedrag
document.onmouseup=new Function("dragapproved=false")

</script><style type="text/css">

#showimage{
position:absolute;
visibility:hidden;

}

#dragbar{
cursor: hand;
cursor: pointer;

min-width: 100px; /*NS6 style to overcome bug*/
}
.topbar{
background-image: url(/images/bossscreentest2.gif);
cursor: pointer;

min-width: 100px; /*NS6 style to overcome bug*/
}
#dragbar #closetext{
font-weight: bold;
margin-right: 1px;
}
</style>

and in body stuff...

<a href="javascript:hidediv()">hide div</a>

will hide the div the game is in and

<a href="/images/bossscreentest.gif javascript:hidediv()" onClick="return enlarge('/images/bossscreentest.gif',event,'center',818,733) " > BOSS</a>

will show the cover..

But I need them both to happen at the same time.. I just cant seem to get the syntax right.

I would appreciate any help, Thanks.

tedster

12:31 am on Jul 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can make one click run two different javascript functions by listing both, but separating them with a semicolon. Something like this might work:

<a href="#" onclick="javascript:hidediv();enlarge('/images/bossscreentest.gif',event,'center',818,733)">Do both</a>