Forum Moderators: open
It use to be if the user click on the special link, but decided they didn't want to click on any other links, the only way to close the menu was to click on the special link once more.
I added a line of code that has the menu close if the window has been re-sized. Which is great.
However, I would like to also add a line of code that will close the menu if anywhere outside the menu was clicked.
I tried window.onclick, but that would close the menu as soon as it would open, so that didn't work.
I also tried window.onblur, but that only works if the user clicks out of the browser, and then back into the browser.
I also tried document.getElementById("ml").onblur and window.document.getElementById("ml").onblur, but that didn't seem to word either.
Any advice? Thanks
I'm now experimenting with this trigger, and I have code that looks like this:
window.onclick=function(){if(event.target==document.getElementByTagName("img")){document.getElementById("s").style.visibility="hidden";}}
This isn't exactly what I'm trying to get at, but I'm trying to get a statement that works.
I'm thinking that it says this:
If a click is made inside the window, then if that click is on an image tag, then set the visibility the id=s to hidden.
In theory that's what the code should do, right?
Thanks anyone for their input on this.
i Had a simmeler problem i one of my scripts.i settled with document.onclick=new Function("hide()");
in the end.
i didnt try this though. put all the html for the page in a DIV tag with an event handeler e.g
<body>
<div id="page" onclick="hide()">
<!--html hear-->
</div><div id="menu">
</div>
</body>
and then just dynamicly write to the div menu
I do not know (did not see your code and the problem itself).
But there are other ways too i suppose. A simple solution imho is : set a global variable as a flag. Default value = 0, for example. The link click event checks this flag and opens menu and sets the flag = 1; any other location click closes the menu, if the flag is 1, and restores the default value. Try this.