Link to home
Start Free TrialLog in
Avatar of codequest
codequest

asked on

Navigate to anchor in already open page

For my ASP net application, I would like to have a browser tab or window open for help. Within the main application  I would like to be able to press one of many buttons and have focus go to specific anchor points with in the "help window.  And if the help window is not open then I need to be able to have it open first.

I'm comfortable creating the JavaScript that would be needed to specify which anchor point to go to depending on context information and the button pressed.

However I'm not clear on the syntax of the window statements that would be needed to do this.
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Not sure if I have understood the question clearly.
But it appears that you are looking for these

Example 1
Example 2
SOLUTION
Avatar of Hans Langer
Hans Langer

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
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
Avatar of codequest
codequest

ASKER

Thanks to all for your inputs.   I implemented this, to try both examples:

function OpenHelp(varHelp) {
    var ws = "TestHelp.aspx"
    switch (varHelp) {
        case 1:
            ws += "#section1"  // does the rest below
            break;
        case 2:
            ws += "#section2"  // does the rest below
            break;

        case 3:
            if (window.win2 == null) {
                window.win2 = window.open('TestHelp.aspx')
            }
            else {
                window.win2 = window.focus("TestHelp.aspx")
            }
            window.win2.location.hash = "section3"
                return
                break;

    }
    window.open(ws, 'helpwindow')
    window.blur()
    window.focus(ws,'helpwindow')
}

Open in new window



@julianH:  your example works pretty much as is, useful, thanks.  
One followup:  In Chrome, your construct both opens the help window and moves the focus to it.  In IE11, on the first use it opens the help window and moves focus to it, however, on the second use it just makes the help window tab blink.   Is there a way to make IE actually go to the help window instead of just making the tab blink?

@GERENTE:  yours is intriguing, however, there are some things I don't understand:
I (naively) rewrote your example as shown above.  (I thought it would need the "else" in order to set the value of "win2").   Things I don't understand:

1) What is the mechanism of "window.win2 = "  (or .win)?  It seems to be creating a window object for later use, however, I can't find any documentation on how that works.  
2)  As you can see, for the "else" condition I tried (again, naively)
window.win2 = window.focus("TestHelp.aspx")  

Open in new window

however that doesn't work to set the win2 object because it is "nothing" when it hit the hash statement.   What's the correct way to set the win2 object (if that's what it's doing) when the window is already open?
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
Thanks for inputs; "got it" on the windows.win variable.  I'll test and post back on the "focus" soon.
I used this.  It forced a new whole browser window, which is better in this instance, and does shift focus to it.

function RspHelp(varAnchor) {
    var winHelp
    var wrkHelpUrl = ""
    wrkHelpUrl = '/../App_Pages/fA50_HELP/fA50_HELP.aspx'
    var ws = wrkHelpUrl + "#" + varAnchor
    winHelp = window.open(ws, 'helppage', 'toolbar=1,location=0,menubar=1')
    winHelp.focus()
    return
}