Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:29
Calling Java functions as menuitems
Poster: realphp
Dated: Thursday October 13 2005 - 0:52:37 BST
Hi Milonic,
Great menu system
Im curious about the best way to deal with using advanced javascript functions, such as a popup window for example called via the menu.
This is the code to our chatroom. When a user clicks the chat button it calls a javascript routine that calculates the users screen resolution then pops a centered window and loads the chatroom in it.
Code:
<a href="/chat/login.php" onclick="chatroom(this.href,'chat','620','540','yes','center');return false" onfocus="this.blur()">Chatroom</a>
Code:
<script language="javascript" type="text/javascript">
var win=null;
function chatroom(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-95)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=0}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=yes';
win=window.open(mypage,myname,settings);}
</script>
var win=null;
function chatroom(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-95)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=0}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=yes';
win=window.open(mypage,myname,settings);}
</script>
I tried to add the function call as a menu item but it didnt work, any idea where I went wrong?
Code:
aI("text=Chatroom;url=chat/login.php" onclick="chatroom(this.href,'chat','620','540','yes','center');return false" onfocus="this.blur()">Chatroom");
------------------
Deep thought...
------------------
What if I wanted to add a javascript menu item down the road? well okay so I add the menu item that calls the function, thats fine, but where do I put the function itself? I cant imagine that I need to add it to every single page, that would be a nightmare, we have over 300 pages and some are dynamically created, so if can we grab it when the menu loads, instead of when the page loads? This would be idea since the menu is shared with all pages.
Well If I can have some thoughts, on this please and thank you
Rob
Poster: Shap5202
Dated: Tuesday October 18 2005 - 15:26:23 BST
You could try this.
Code:
aI("text=Chatroom;url=javascript:chatroom('chat/login.php','chat','620','540','yes','center');");
That would create a menu item with the Text of 'Chatroom' and call the chatroom javascript function when it is clicked.