Link to home
Start Free TrialLog in
Avatar of desk
desk

asked on

Cross Frame DHTML Menu

I created a cross frame menu that displays across two frames.   I have a problem when I try to display the menu over a selection box on the bottom frame, the selection box has a higher index order and overwrites the menu.  I haven't found a way to change the selection box index order.  Does anyone know how to correct this problem?
SOLUTION
Avatar of Stucco
Stucco

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of msa2003
msa2003

Actually, you need to re-write the menu to use inline frames instead of pure tables or CSS. Inline frames (<iframe>) are allwais displayed over the form elements (like <select> <textarea> or <input>).

I have just used the following code to show the iframe menu capabilities:

<html>
<head>
<title>Menu example</title>
<script>

itemHeight=20;

function addMenu(name, width, x, y, values, submenus, visible)
{
  h=(itemHeight+1)*values.length+1;
  w=width+2;
  d=document;
  d.write('<div id="'+name+'d" style="position: absolute; top: '+y+'; left: '+x+';">');
  d.write('<iframe id="'+name+'i" scrolling="no" frameborder="0" width="'+w+'" height="'+h+'"> </iframe></div>');
  d=document.frames[name+'i'].document;
  d.write('<html><head><style>');
  d.write('body { margin: 0; }');
  d.write('td { background-color: #C0C0FF; }');
  d.write('table { background-color: #8080FF; }');
  d.write('</style><scr'+'ipt> function over(id) { document.all.item(id,0).style.backgroundColor = \'#A0A0FF\'; }');
  d.write('function out(id) { document.all.item(id,0).style.backgroundColor = \'#C0C0FF\'; }');
  d.write('function show(id) { parent.document.all.item(id,0).style.visibility=\'\'; }');
  d.write('function hide(id) { parent.document.all.item(id,0).style.visibility=\'hidden\'; } </scr'+'ipt>');
  d.write('</head><body><table width="100%" cellspacing="1" cellpadding="0">');
  for (i = 0; i < values.length; i++)
  {
    tid=name+'n'+i;
    d.write('<tr><td id="'+tid+'" onMouseOver="over(\''+tid+'\');');
    if (submenus[i] != '')
    {
      d.write('show(\''+submenus[i]+'d\');');
    }
    d.write('" onMouseOut="out(\''+tid+'\');');
    if (submenus[i] != '')
    {
      d.write('hide(\''+submenus[i]+'d\');');
    }
    d.write('" align="center" height="'+itemHeight+'">'+values[i]+'</td></tr>');
  }
  d.write('</table></body></html>');
  if (!visible)
  {
    document.all.item(name+'d',0).style.visibility = 'hidden';
  }
}

</script>
</head>
<body bgcolor="#FFFFC0">
<h1>Submenu draft demo</h1>
<table><tr><td width="140">&nbsp;</td>
<td><select>
<option value="1">option1
<option value="2">option2
</select></td>
</tr></table>
<script>
  addMenu('m1',100,10,55,['item 1','item 2'],['s1','s2'],true);
  addMenu('s1',100,111,55,['subitem 1.1','subitem 1.2','subitem 1.3'],['','',''],false);
  addMenu('s2',100,111,76,['subitem 2.1','subitem 2.2','subitem 2.3'],['','',''],false);
</script>
</body>
</html>

This is not to be the complete solution, but I could finish it if you'll need it.

Best regards
Serge
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Using an iframe is a valid approach, but if you are going to do that you should be using DOM1 compliant code.  What you have there is IE only.  Mozilla based browsers like Netscrap6+ do not support document.all

Cd&
> but if you are going to do that you should be using DOM1 compliant code.  What you have there is IE only.  Mozilla
>based browsers like Netscrap6+ do not support document.all

I know that. Thanks. I have already written the cross-browser (tested with Opera 7, NN6/7/Mozilla, IE5.5+) code to manage iframe floating windows (used it in my custom combo box), but still didn't implement it in the menu script. Let's say I'm too laisy. But I am ready to do so. The text below is just an illustration of how to create iframe menus.

Best regards
Serge
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
how about a comment from the author, or did he forget about the question?
Avatar of desk

ASKER

Thanks for the variety of solutions posted for the problem.  They are all good solutions to the problem but,
I'm leaning towards the iframe implementation because I feel it would be easier to maintain.

Stucco - I like the look and feel of your selection box.  The author did not abandoned the question he has
      been on vacation, unfortunately golfing in the rain.

- Michael
Glad we could help.  Thanks for the A. :^)

Cd&
:-) Glad you got your question answered.
Thx for the assist points,

Stucco
Thank you for "A". If you have any questions, please ask. Now I'm working with this code.
The accepted code above does not work correctly in all browsers and platforms, so its not a very good solution.

I've created the following pages utilzing the code above and other methods for testing in your own browsers:
http://www.godesign.com/~tracys/testing/index.html (IFRAME menu above over textarea as in accepted answer's 1.html code)
http://www.godesign.com/~tracys/testing/index2.html (IFRAME menu over another IFRAME - modified version of accepted answer's 1.html code)
http://www.godesign.com/~tracys/testing/index3.html (uses z-index to place IFRAME on top of DIV and vice versa - works for IE5.5+ and partially in NS7)
http://www.godesign.com/~tracys/testing/index4.html (hide IFRAME with JavaScript and style.visibility='hidden')

Working correctly:
IE 5.5 - Windows
IE 6 - Windows
Netscape 7.1 - Windows (mostly)

Not working correctly:
Netscape 4.8 - Windows (no IFRAMES support, use LAYER instead)
Netscape 6 - Windows (partial support)
Safari 1.0 (v85.5) - Mac
IE 5.2.2 - Mac

Many solutions have been suggested:
http://dotnetjunkies.com/weblog/jking/posts/488.aspx (control z-index of IFRAME with iframe.style.zIndex - works for IE only, I believe)
http://www.webreference.com/programming/javascript/form/ (hide DIV with JavaScript style.visibility="hidden", similar to index4.html above)
http://beta.experts-exchange.com/questions/20407376/DIV-over-IFRAME-in-Opera-6.html (hide IFRAME with JavaScript and style.visibility='hidden', same as index4.html above)
http://www.faqts.com/knowledge_base/view.phtml/aid/10824/fid/53 (only for Netscape/Mozilla)
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&threadm=3c5eab99.86075379%40news.rdu.bellsouth.net&rnum=5&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26safe%3Doff%26q%3Diframe%2Bstyle%2BzIndex (uses z-index to place IFRAME on top of DIV and vice versa - works for IE only I believe; same as index3.html above)

Perhaps the easiest technique is to "...consider placing the form in a positioned element that can have visibility toggled. Then "hide" the form when other positioned elements are being dragged, and "show" it only when necessary." -http://www.webreference.com/dhtml/diner/seethru/6.html

Implementing this technique is described here in great detail:
http://www.webreference.com/programming/javascript/form/

To be specific though, there does not seem to be a technique or even combination of techniques that works for every browser and platform. Can anyone comment further?

Graham Spice