Hi
I am having trouble implementing a context-sensitive pop-up help window using the javascript method called window.open. Although I have the basic pop-up window working just fine, Im having a lot of trouble implementing a customer request that I was given yesterday. Im stuck and I would really appreciate it if you could help me. Listed below are the steps Ive taken, together with my code samples and questions.
Currently, I can successfully navigate to any one of our applications 68 UI windows and click the Help menu item on our applications top tool bar. This Help menu item is in a jsp called pageHeader.jsp. Each of our 68 UI windows includes this pageheader.jsp by entering the following statement at the top of their jsp:
<%@ include file=pageheader.jsp%>
Within the pageheader.jsp, Ive written code so that when the Help menu item is clicked, I execute a javascript function to open the pop up help window. Here is the existing code in my JSP page for the Help menu item:
<td style="background-color: #fff;background-image: url(images/topbar_bg.jpg);background-repeat: repeat-x;margin: 0;padding: 0;">
<div style="vertical-align: middle;cursor: help;padding: 0 4px 0 4px;white-space: nowrap;" onClick="javascript:open_ContextSensitiveHelpWindow('<%=tagName%>');">
<strong class="newtxt">Help</strong></div>
</td>
Here is my javascript function called open_ContextSensitiveHelpWindow
<script type="text/javascript">
function open_ContextSensitiveHelpWindow(tagName)
{
window.open("help/help.html?context=help&topic="+tagName+"&","help_win","menubar=0,resizable=1,width=700,height=350,addressbar=0,scrollbars=1,left=275,top=275");
}
</script>
As I mentioned above, this code works fine. Unfortunately, if, after I click the Help menu item and pop up the Help window, I then decide to switch to another UI screen, I can click the Help menu item again and a second pop up window will appear. In fact, even if I stay on the current UI window and click Help, another pop up window will appear. The customer has requested that only 1 pop up window appear. Once this window is open, then the customer can switch to any of the 68 UI windows and click Help, and then only the contents of the existing Help window will change (I actually got the contents to change during an experiment by coding window.location.href = newURL.) But the customer does not want multiple pop up windows to appear.
Despite my research and experiments, Im unable to implement this request. The only approach Ive tried is to save a reference to the pop up help window in a hidden field on the pageheader.jsp. I was thinking that if I could save the window reference to the hidden field, then perhaps I could store it in the users session where it would be available each time the pageheader.jsp is loaded. The code below works if I stay on the samd UI application window. But if I switch UI windows, then I lose the reference to my pop-up window. Can you tell me if its possible to save the window reference in the session (or request/response objects) from my hidden field? If yes, am I taking the correct approach? What more do I need to do to get the window reference into the session? If not, is there a different approach I can use to implement the customers request?
Here is my experimental code:
I call the following function to initialize the hidden input value during the loading of pagehelp.jsp
<body onload="javascript: doit();">
Here is my hidden field:
<td><input type="hidden" id="popupWin" name="popupWin"/></td>
Here are my javascript functions
<script type="text/javascript">
function open_ContextSensitiveHelpWindow(tagName)
{
win = document.getElementById("popupWin").value;
if(typeof(win) == undefined")
{
win=window.open("help/help.html?context=help&topic="+tagName+"&","help_win","resizable=1,width=700,height=350,scrollbars=1,left=275,top=275");
document.getElementById("popupWin").value = win;
}
else if (win.closed)
{
win=window.open("help/help.html?context=help&topic="+tagName+"&","help_win","resizable=1,width=700,height=350,scrollbars=1,left=275,top=275");
}
else
{
// Get the existing URL in the popup window and change the topic (experiment to test
// changing topics within the window
var url = win.location.href;
var topicIndex = url.indexOf("topic=");
var suburl = url.substring(0, topicIndex);
var newurl = suburl + "topic=main_search&";
win.location.href = newurl;
}
win.focus();
}
function doit()
{
var test = 99;
document.getElementById("popupWin").value = test;
}
One last question, Ive noticed that every time I save the window reference to the hidden field, when I retrieve it, the javascript typeof always says it is a string. Upon calling the window.open function a second time, I can see that the window reference is a [object], but the typeof keeps telling me string. Does that value= field on the hidden field always report values of type string?
Thank you for your help.
And your problem should be solved by using always the same windowName for all popups. The window name parameter ensures that the opened window with same name is reused.
Therefore this should work:
Open in new window