Opening a New Browser Window

Joined
Feb 12, 2006
Messages
18
Location
Australia
Programming Experience
10+
I'm trying to open a new browser window whenever the user selects a document from a list. The list is correctly populated but to demonstrate the problem I've hard-coded the file name in the following example:

PrivateSub DisplayPageInNewWindow(ByVal PageName As String)
'Response.Write("<script type='text/javascript'>detailedresults=window.open(PageName);</script>")
Response.Write("<script language='javascript'>" & vbCrLf)
Response.Write("wndCht=window.open('QP_050.htm','','width=600, height=400,toobar=no,addressbar=no,menubar=no,scrollbars=yes,resizable=yes')")
Response.Write("<" & "/" & "script" & ">" & vbCrLf)
EndSub

This does not fail but simply redisplays the current window. The correct document displays if I simply use Response.Redirect (obviously not in a separate window).

Any help greatly appreciated!
 
Last edited:
Looks like you have the current page name hardcoded in... use the PageName variable you passed into your sub.

Also, you don't need all that white space stuff... for example, you could change that to:
response.write("<script language=""javascript"">")
response.write("wndCht=window.open(PageName,'','width=600...');")
response.write("</script>")

javascript ignores white spaces and linebreaks anyway, plus white space adds to the file size of the web page that is ultimately sent to the browser.
 
Thanks for the feedback however it works when I hard-code the page name but NOT when I replace it with the parameter name. I've stepped through the code debugger and the parameter definitely contains the correct page name.

When I use the parameter name the page doesn't display at all, the current page just flickers and refreshes. Everything I've read says that what I'm doing SHOULD work (when I use a parameter rather than hard-coding) but for some reason it isn't.

I'm sure I'm just missing something very simple but I haven't been able to work out just what that simple step is.
 
Try using page.registerstartupscript() instead of response.write. so put your entire script string into the registerstartupscript command and after the postback the window should open.
 
Thanks for the prompt feedback. I've already tried that and it didn't work either. I know how to use the function (page.registerstartupscript) because I've used it successfully to force the cursor into the first field on an aspx page.

Everything you're suggesting is consistent with everything else I've seen and it therefore must be something that I'm not doing correctly, i.e. I've missed a setting or something.

I've checked browser settings for popup blockers etc. but it's almost like it doesn't run the page_load event when it redisplays the page or, more likely, I've got the code in the wrong place when I check the isPostBack event.

I'll keep plugging away but I do appreciate your efforts to resolve this.
 
OH... try this: move your registerstartupscript or response.write to the page_prerender event. I bet that works :)

The problem is, the page_load event occurs before the postdata and events are raised, so if you try to access the listbox in the onload event to see which item was selected, you will not find the selected item. You have to do that work in the prerender event which happens after all of the client-side user changes have been processed by the server.

My guess that is why it's working for when you hardcode the name in, but not when you try to dynamically populate the URL from the selection.

I hope that works for you!
 
Back
Top