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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to all for your inputs. I implemented this, to try both examples:
@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)
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')
}
@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")
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for inputs; "got it" on the windows.win variable. I'll test and post back on the "focus" soon.
ASKER
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/f A50_HELP.a spx'
var ws = wrkHelpUrl + "#" + varAnchor
winHelp = window.open(ws, 'helppage', 'toolbar=1,location=0,menu bar=1')
winHelp.focus()
return
}
function RspHelp(varAnchor) {
var winHelp
var wrkHelpUrl = ""
wrkHelpUrl = '/../App_Pages/fA50_HELP/f
var ws = wrkHelpUrl + "#" + varAnchor
winHelp = window.open(ws, 'helppage', 'toolbar=1,location=0,menu
winHelp.focus()
return
}
But it appears that you are looking for these
Example 1
Example 2