Hide a div after the user clicks on a child menu item - javascript

I'm working with a javascript menu and need help hiding the menu after the user clicks a link in the child menu. The menu works well out of the box, except when the user clicks the back button on their browser it remains stuck open.
The code that hides the child menu:
divref.style.visibility = "hidden";
I think it needs to go in this section of code:
this.finishOpeningChild = function(divref, ulref, maxwidth) {
this.isChildMenuOpen = true;
this.isChildMenuClosed = false;
ulref.style.left = "0px";
divref.style.width = maxwidth + "px";
}
How do I make the browser look for the onClick scenario then call: divref.style.visibility = "hidden"; in this situation?

Not sure in what context this is all running, but perhaps you have a statement on the page which checks to see if the menu is open, and closes it if it is, this would happens on page load ... so if the user clicks the back button and ends up on the page the below check would run ...
if ('hidden' != divref.style.visibility) divref.style.visibility = 'hidden';

Related

aspx/c# Refresh on closing popup

I have a little problem with my code.
I have an asp:Wizard element, in which I have few steps.
In one step, I click on a button that open a popup with window.open to select a datetime.
When I selected one, the popup is closing, but the datetime is not visible in my parent window (but it's there, because when I click again on my window.open it's "reloading" my page and the date is now visible)
I already tried to reload my parent's page when I close the popup with window.parent.opener.location.reload but this solution make me lose the active step of my wizard.
So what I need is a partial refresh of my page that keeps the current step.
below is the code
My opener:
var childWindow = window.open("../../Utils/CalendarPopup.aspx?DatePred=Stateme‌​‌​ntDateFrom", "", "height=280; width=285;);
childWindow.onunload = function ()
{ // Where i need to reload }
My popup:
Session[Request.Params["DatePred"]] = CalendarSelectDate.SelectedDate;
Session["CalendarPopupCanceled"] = 0;
this.ClosePage();
The data loading:
if (Session["StatementDateFrom"] != null)
{
{
(WizardProcess.FindControl("DtTxtBxStatementDateFrom") as Syncfusion.Web.UI.WebControls.Shared.DateTimeTextBox).IsNullDate = false;
(WizardProcess.FindControl("DtTxtBxStatementDateFrom") as Syncfusion.Web.UI.WebControls.Shared.DateTimeTextBox).Value = System.Convert.ToDateTime(Session["StatementDateFrom"]);
}
Session["StatementDateFrom"] = null;
}
Thanks in advance
i don't know how you wrote your code, but why you need to reload the child window. If you have a control (for example a textbox) that displays the datetime you selected from the childWindow, then you can set the control's value equal to the selected datetime. This should be easier than trying to refresh only the wizard!

How to attach a context menu to a button

I'm trying to attach a context menu to a button on my toolbar.
Here is my code:
contex_order = new dhtmlXMenuObject();
contex_order.renderAsContextMenu();
contex_order.loadStruct(cont_m);
...
toolbarOrder = new dhtmlXToolbarObject("tab_ord");
toolbarOrder.setIconsPath("dhtmlx/codebase/imgs/");
toolbarOrder.attachEvent("onClick", function(id){
if (id=="save")
contex_order.showContextMenu(100,50)
});
But clicking on that button doesn't make the context menu show up. There is no error in the browser console, just nothing.
Did anyone have such kind of a problem? How can I make the menu be shown?
Please, try to call the showContextMenu() method with the timeout:
setTimeout(function() {
contex_order.showContextMenu(100,50)
}, 50)
as the menu shows up at the same time with the button click this button click closes the menu at the same time.

How do I simultaneously hide a div and redirect to a new HTML page when something is clicked once?

I currently have this code
Next »
which in one click is supposed to display a new page, One.cshtml and hide index.cshtml (the current page). However, it takes 2 clicks in order for this to happen as the first click displays One.cshtml and doesn't hide index.cshtml and the second click hides finally hides index.cshtml.
Here is the code for the hide function if it helps:
function hide(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
I'm also having trouble understanding why index.cshtml doesn't disappear automatically when it is redirected to One.cshtml. I feel like I must be doing something incorrectly in general.
<a onClick="hideandgo('page1')" class="next">Next »</a>
function hideandgo(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
window.location.href = /#/routeOne;
}

Firefox extension: get click data when context menu

In my extension I want to hide/show items on the context menu based on the url I get:
from a link if the user opens the context menu over one,
from the text selected, also if the user opens the context menu over the text.
In the function to show/hide items in the context menu I do the following check:
if (gContextMenu.onLink) {
url = gContextMenu.target.href;
}
if (gContextMenu.isTextSelected) {
url = content.window.getSelection();
}
If some text is selected in the page, and the user opens the context menu over a link, both conditions are true. Also, if some text is selected, and the user opens the context menu anywhere in the page (over the selection or not), the isTextSelected flag is also true.
Is there a way I can detect what is the real element over which the user has used the right click? How can I know if the right click was over the selected text or not?
First of all, there is gContextMenu.target, which contains the Node which was under the cursor, if any (aka. it might be null in very rare cases).
The gContextMenu code actually uses gContextMenu.target to initialize things like .onLink
As for checking if the the focused node is actually contained within the current selection, you can use .getSelection().containsNode() on the focused document.
var isFocusedNodeInCurrentSelection = false;
var selection = gContextMenu.focusedWindow &&
gContextMenu.focusedWindow.getSelection();
if (selection) {
isFocusedNodeInCurrentSelection =
selection.containsNode(gContextMenu.target, true);
}
// Do something with that information.

javascript is affecting every anchor, I want to make some exempt

so I have one script that scrolls the whole page smoothly. Nice script. It uses anchors to do this. So the NAvigation Menu basically says "ABOUT ME" or whatever, and when clicked the whole page scrolls to the ABOUT ME section. But what its programmed to do is when I click on an internal anchor link, it bring the browser view to the TOP, LEFT. which works fine, since I want to scroll the entire page.
BUT.
I am using another script that allows me to click an option on a menu, and a little window should pop up and give me the info. BUT instead, the whole page moves, thanks to the previous scrolling script, and puts the new pop TOP, LEFT.
Soooo? any ideas?
init: function () {
var lnks = document.getElementsByTagName('a');
for (var i = 0, lnk; lnk = lnks[i]; i++) {
if ((lnk.href && lnk.href.indexOf('#') != -1) && ((lnk.pathname == location.pathname) || ('/' + lnk.pathname == location.pathname)) && (lnk.search == location.search)) {
addEvent(lnk, 'click', HtinyScrolling.initScroll, false);
lnk.onclick = function () {
return false;
} // Safari
}
}
Rewrite the scrolling script so it does not affect the anchors in the menu. Without seeing any code it is difficult for me to say exactly what to change.
The best way to solve this would be to either make the scrolling script only affect anchors of a specific css class such as .scrollable, or alternatively make it not affect anchors with a specific class for example if the option menu has every option with class .option then disable your script for anchors with class .option. If I could see the relevant parts of your code I could help further

Categories

Resources