xunling: ein <div panel per button auf und zu schliessen document write

hi,

ich versuche mit dieser funktion


<script language="JavaScript" type="text/javascript">
var chatWindowOpen = false;
//Function for initializating the page.
function test1() {
  if (chatWindowOpen == false) {
    chatWindowOpen = 1;
    spacerDim();
  } else {
    chatWindowOpen = 0;
    spacerDim();
  }
}
function spacerDim() {
	if (chatWindowOpen == true) {
		document.write ("<div id=\"div1\" style=\"position: absolute; width: 110px; height: 24px; left: 687px; top:10px; z-index: 110; background: #b1b1b1\"><span class=\"style2\"><font color=\"#000000\"><span onClick=\"test1()\">chatfenster &ouml;ffnen</span></font></span></div>");
	} else {
		document.write ("<div id=\"div1\" style=\"position: absolute; width: 110px; height: 24px; left: 687px; top:10px; z-index: 110; background: #b1b1b1\"><span class=\"style2\"><font color=\"#000000\"><span onClick=\"test1()\">1chatfenster &ouml;ffnen</span></font></span></div>");
	}
	
	
	
	/* var tmp0 = window.location.href;
	if (tmp0.search(/height=/) != -1) {
		var tmp1 = window.location.href;
		var tmp2 = tmp1.indexOf("height=") + 7;
		var tmp3 = tmp1.substr(tmp2); // width
		var tmp4 = 240 - (786 - tmp3);
			
		if (tmp3 > 787) {
			document.write ("<img src=\"images/spacer.gif\" width=\"1\" height=\"240\">");
		} else {
			document.write ("<img src=\"images/spacer.gif\" width=\"1\" height=\" " + tmp4 + " \">");
		}
	} else {
		document.write ("<img src=\"images/spacer.gif\" width=\"1\" height=\"240\">");
	} */
}
</script>

ein button fuer ein fenster mit chatfunktion zu machen, ich weiss nicht, wie ich die globale variable chatWindowOpen auf 1 oder false stellen kann, wenn sich das fenster geoeffnet hat, habe ich einen endlos loop, und die seite laesst sich nicht mehr aufrufen,

der name, spacerDim ist falsch vergeben, und soll das chatfenster schreiben, ... die anderen variablen, stammen aus einer anderen seite

<html>
<head>
<title>asd ajshdkja hsdkjahd kasd - aksd jalskdjaslkdjlksad</title>
<link href="style25_3.css" rel="stylesheet" type="text/css">
<style type="text/css" media="screen">
.chat_time {
	font-style: italic;
	font-size: 9px;
}
</style>
<script language="JavaScript" type="text/javascript">
var sendReq = getXmlHttpRequestObject();
var receiveReq = getXmlHttpRequestObject();
var lastMessage = 0;
var mTimer;
var chatWindowOpen = false;
//Function for initializating the page.
function test1() {
  if (chatWindowOpen == false) {
    chatWindowOpen = 1;
    spacerDim();
  } else {
    chatWindowOpen = 0;
    spacerDim();
  }
}
function spacerDim() {
	if (chatWindowOpen == true) {
		document.write ("<div id=\"div1\" style=\"position: absolute; width: 110px; height: 24px; left: 687px; top:10px; z-index: 110; background: #b1b1b1\"><span class=\"style2\"><font color=\"#000000\"><span onClick=\"test1()\">chatfenster &ouml;ffnen</span></font></span></div>");
	} else {
		document.write ("<div id=\"div1\" style=\"position: absolute; width: 110px; height: 24px; left: 687px; top:10px; z-index: 110; background: #b1b1b1\"><span class=\"style2\"><font color=\"#000000\"><span onClick=\"test1()\">1chatfenster &ouml;ffnen</span></font></span></div>");
	}
	
	
	
	/* var tmp0 = window.location.href;
	if (tmp0.search(/height=/) != -1) {
		var tmp1 = window.location.href;
		var tmp2 = tmp1.indexOf("height=") + 7;
		var tmp3 = tmp1.substr(tmp2); // width
		var tmp4 = 240 - (786 - tmp3);
			
		if (tmp3 > 787) {
			document.write ("<img src=\"images/spacer.gif\" width=\"1\" height=\"240\">");
		} else {
			document.write ("<img src=\"images/spacer.gif\" width=\"1\" height=\" " + tmp4 + " \">");
		}
	} else {
		document.write ("<img src=\"images/spacer.gif\" width=\"1\" height=\"240\">");
	} */
}
function startChat() {
	//Set the focus to the Message Box.
	document.getElementById('txt_message').focus();
	//Start Recieving Messages.
	getChatText();
}
//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object.  Consider upgrading your browser.';
	}
}

//Gets the current messages from the server
function getChatText() {
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
		receiveReq.open("GET", 'getChat.php?chat=1&last=' + lastMessage, true);
		receiveReq.onreadystatechange = handleReceiveChat;
		receiveReq.send(null);
	}			
}
//Add a message to the chat server.
function sendChatText() {
	if(document.getElementById('txt_message').value == '') {
		alert("You have not entered a message");
		return;
	}
	if (sendReq.readyState == 4 || sendReq.readyState == 0) {
		sendReq.open("POST", 'getChat.php?chat=1&last=' + lastMessage, true);
		sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		sendReq.onreadystatechange = handleSendChat;
		var param = 'message=' + document.getElementById('txt_message').value;
		param += '&name=Ryan Smith';
		param += '&chat=1';
		sendReq.send(param);
		document.getElementById('txt_message').value = '';
	}							
}
//When our message has been sent, update our page.
function handleSendChat() {
	//Clear out the existing timer so we don't have
	//multiple timer instances running.
	clearInterval(mTimer);
	getChatText();
}
//Function for handling the return of chat text
function handleReceiveChat() {
	if (receiveReq.readyState == 4) {
		var chat_div = document.getElementById('div_chat');
		var xmldoc = receiveReq.responseXML;
		var message_nodes = xmldoc.getElementsByTagName("message");
		var n_messages = message_nodes.length
		for (i = 0; i < n_messages; i++) {
			var user_node = message_nodes[i].getElementsByTagName("user");
			var text_node = message_nodes[i].getElementsByTagName("text");
			var time_node = message_nodes[i].getElementsByTagName("time");
			chat_div.innerHTML += user_node[0].firstChild.nodeValue + '&nbsp;';
			chat_div.innerHTML += '<font class="chat_time">' + time_node[0].firstChild.nodeValue + '</font><br />';
			chat_div.innerHTML += text_node[0].firstChild.nodeValue + '<br />';
			chat_div.scrollTop = chat_div.scrollHeight;
			lastMessage = (message_nodes[i].getAttribute('id'));
		}
		mTimer = setTimeout('getChatText();',2000); //Refresh our chat in 2 seconds
	}
}
//This functions handles when the user presses enter.  Instead of submitting the form, we
//send a new message to the server and return false.
function blockSubmit() {
	sendChatText();
	return false;
}
//This cleans out the database so we can start a new chat session.
function resetChat() {
	if (sendReq.readyState == 4 || sendReq.readyState == 0) {
		sendReq.open("POST", 'getChat.php?chat=1&last=' + lastMessage, true);
		sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		sendReq.onreadystatechange = handleResetChat;
		var param = 'action=reset';
		sendReq.send(param);
		document.getElementById('txt_message').value = '';
	}							
}
//This function handles the response after the page has been refreshed.
function handleResetChat() {
	document.getElementById('div_chat').innerHTML = '';
	getChatText();
}
	
</script>
</head>
<body marginwidth="0" marginheight="0" onload="javascript:startChat();" >
<form id="frmmain" name="frmmain" onsubmit="return blockSubmit();">
<div position="relative">
  <?php // ...

  // increase einheite count, pro einheit um 19px


  ?>
  <div style="position: absolute; width: 200px; height: 19px; left: 540px; top: 260; z-index: 100; background: #ececec;" align="right"><span style="font-family: Calibri; font-size: 13">text asdf blabla</span></div>
  <div style="position: absolute; width: 110px; height: 19px; left: 425px; top: 260; z-index: 100; background: #ececec;"><span style="font-family: Calibri; font-size: 13">credits</span></div>

  <div style="position: absolute; width: 350px; height: 126px; left: 389px; top: 294; z-index: 100; background: #ececec;" align="right"><span class="style1"><font color="#000000">raumflugzeuge produzieren</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
  <table width="270" cellpadding="0" cellspacing="0" border="1">
          <tr>
            <td align="right"><a href="index.php?production_queue=+1space_ship" class="style1"><font color="#000000">raumflotte</font>n</a></td>
	    <td align="right" width="43"><a href="index.php?production_queue=+1space_ship" class="style1"><font color="#000000">80 $</font></a></td>
            <td rowspan="8" width="18">&nbsp;</td>
          </tr>
          <tr>
            <td align="right"><a href="index.php?production_queue=+1freighter" class="style1"><font color="#000000">freighter</font></a></td>
	    <td align="right"><a href="index.php?production_queue=+1freighter" class="style1"><font color="#000000">80 $</font></a></td>
          </tr>
          <tr>
            <td align="right"><a href="index.php?production_queue=+1spacemine" class="style1"><font color="#000000">spacemine</font></a></td>
	    <td align="right"><a href="index.php?production_queue=+1spacemine" class="style1"><font color="#000000">30 $</font></a></td>
          </tr>
      </table></div>
  <div style="position: absolute; width: 350px; height: 150px; left: 389px; top: 436; z-index: 100; background: #ececec;" align="right"><span class="style1"><font color="#000000">einheiten queue</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
  <table width="270" cellpadding="0" cellspacing="0" border="1">
          <tr>
            <td align="right"><span class="style1"><font color="#000000">spaceship</font></span></td>
            <td rowspan="8" width="18">&nbsp;</td>
          </tr>
      </table></div>
  <?php
  /*
  <div id="div1" style="position: absolute; width: 110px; height: 24px; left: 687px; top:10px; z-index: 110; background: #b1b1b1"><span class="style2"><font color="#000000"><span onClick="test1()">chatfenster &ouml;ffnen</span></font></span></div>
  */


  ?>
  <script type="text/javascript">spacerDim();</script>
















</div>
</form>
</body>
</html>

dankeschoen

  1. Hallo,

    nich document.write und dann noch mit escapes der anführungszeichen.

    setzte das div auf visibility:hidden bzw. display:none per css und ändere dann die eigentschaft.

    Gruß

    jobo