Open New Window using Response.Write

I am trying to use the following code to open a new window and on my web browser I just get Page Cannot be displayed but I am not sure where the error is.

Response.write("<script>");
Response.Write("window.open('" & strRedirectURL & "','mywindow','width=900,height=625 resizable=yes')");
Response.Write("</script>");

hwdevAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lambdabunkerCommented:
are you getting your popup opening up in a new windows.?
probably your redirect url is incorrect.
0
debuggerauCommented:
Wont you need a LF/CR at the end of each line?

0
debuggerauCommented:
hmm, getting tired, don't think thats going to be it, better get home...
How about response.Redirect?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

jarwCommented:
As debuggerau said, Response.Redirect may be a better option depending on what you are trying to do.

I can't quite tell from your code which language you are using. Is this classic ASP with VBScript or ASP.NET with VB.NET. Either way... you don't need the semicolons (;) at the end of each line, do you?

A couple examples in ASP/VBScript are given below. One is pretty close to yours. The other is another way you might do this. Note that the script must be inside the BODY tag if you want it to execute as the browser is loading.
<!-- Example 1 -->
<html>
<head>
</head>
<body>
<%
Dim strRedirectURL
strRedirectURL = "http://www.google.com"
 
Response.Write("<script>")
Response.Write("window.open('" & strRedirectURL & "','mywindow','width=900,height=625 resizable=yes')")
Response.Write("</script>")
%>
</body>
</html>
 
<!-- Example 2 -->

Open in new window

0
hwdevAuthor Commented:
This is classic ASP and the page is code that I am trying to implement from a vendor which is JavaScript and the redirect will not work because I want to open the new window and resize. I would appreciate any other responses because I am on a deadline.  Than you
0
jarwCommented:
Hmmm... my second example didn't seem to make it. Here it is.
<html>
<head>
</head>
<body>
<%
Dim strRedirectURL
strRedirectURL = "http://www.google.com"
%>
 
<script>
window.open('<%=strRedirectURL%>','mywindow','width=900,height=625 resizable=yes');
</script>
</body>
</html>

Open in new window

0
jarwCommented:
You also have the option of opening the new window after the page loads. See the code below for an example of how to do that.
<%
Dim strRedirectURL
strRedirectURL = "http://www.google.com"
%>
<html>
<head>
<script>
function OpenWindow()
{
   window.open('<%=strRedirectURL%>','mywindow','width=900,height=625 resizable=yes');
}
</script>
</head>
<body onload="OpenWindow();">
</body>
</html>

Open in new window

0
hwdevAuthor Commented:
Your example 2 is what I want and it opens the new window but it leaves a blank window in the background, so how do I keep that window available in the background, I thought return false worked but I must not be using the correct syntax.  

window.open('<%=strRedirectURL%>','mywindow','width=900,height=625 resizable=yes');

This is when I had it in my form and it opened up in a new window and left the orig window in the background like I need it.
<input id="submit1" name="submit1" type="submit" value="LOGIN" onClick="CheckValues(); window.open('http://webstg/tzg/bcm/login/structure/login_fr.jsp? ','mywindow','width=900,height=625 resizable=yes');return false;">
0
jarwCommented:
Maybe your form is being submitted on the background window, causing it to go blank. What happens if you change your input to be a button type instead of a submit type? That is, make your code look something like this:

<input id="submit1" name="submit1" type="button" value="LOGIN"... etc.
0
hwdevAuthor Commented:
Originally pg1.asp had the form and the onClick I mentioned above and it opened the new window and kept the form in the background and all was good. I had to change the process where the form action on pg1.asp went to pg2.asp, I did some more validation and then issued window.open('<%=strRedirectURL%>','mywindow','width=900,height=625 resizable=yes'); and it opened just fine but left the background blank and you are saying that is because the form was submitted on pg1.asp.   Is there any way to keep that original form up??        

0
jarwCommented:
If you want to go back to pg1.asp after your processing in pg2.asp (and after the new window has opened), try calling this AFTER the call to window.open:

   document.location.href = "pg1.asp";

This will cause the original window to be reloaded with pg1.asp.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hwdevAuthor Commented:
I added the document.location after the window.open to go to a particular page depending on the user and everything works great!!   Thank You
0
hwdevAuthor Commented:
I appreciate the prompt responses
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Networking

From novice to tech pro — start learning today.