Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use response.redirect and open new browser window?

Status
Not open for further replies.

grandfatheroften

Programmer
May 23, 2003
11
US
My application for online giving to a nonprofit org. uses ASP to list projects from database and sends uses URL from selected project in table to activate giving pages at an outside service that handles the transactions.

All works well, using the following code to request the link and to redirect to the outside URL.

<%
project_link=trim(request.form("link"))

response.redirect project_link
%>

But it opens the outside page in the same browser window. I want it to open a new window, so I have tried adding:

target="blank"

--- with and without a comma after 'project_link,' with and without parentheses, etc. No matter which variation, I get one compilation error or another.

Any help will be appreciated.


 
ASP cannot control the browser window directly...so you need to use javascript for this:

Try this:
Code:
<%
project_link=trim(request.form("link"))
%>
<script> 
window.open(project_link,
null, "height=500, width=760, status=yes, toolbar=no, 
menubar=no, location=no"); 
</script> 
<%
'your remaining asp code if any...
%>

-DNG
 
DNG-

Thanks, you have given me the main clue--that I need to use JavaScript to open the new window.

I'm no longer receiving any error messages with your code, but only the .asp page shows. It isn't opening a new browser window at the outside site based on the link.

I'll play with it a bit to see if I can figure out why it isn't working.

-GOT
 
are u sure you have the code right...let me warn you, javascript is case sensitive...

-DNG
 
DNG,

Yes, I simply copied your code to my .asp file and, as an old C & C++ programmer, I know about javascript being case sensitive.

Does placement in the .asp file relative to the HTML make a difference. I tried it in several locations--above the <HTML>, inside the header, and in the body; none worked.

The .asp page comes up with my HTML text heading and buttons, but no new window opens.

Any other thoughts?

-GOT
 
ok..i ran the code...and was not getting the window to open...but the problem was a silly one...you shud have the window.open line should be in a single line...

<%
project_link=trim(request.form("link"))
%>
<script>
[red]window.open(project_link,
null, "height=500, width=760, status=yes, toolbar=no,
menubar=no, location=no"); [/red]
</script>
<%
'your remaining asp code if any...
%>

the red part shud be in a single line...

-DNG
 

try this:

Code:
<%
 dim sLink
 sLink = trim(request.form("link"))
%>
<script type="text/Javascript">
window.open("<%=sLink%>", null, "height=500, width=760, status=yes, toolbar=no,menubar=no, location=no");
</script>

A smile is worth a thousand kind words. So smile, it's easy! :)
 
i dont think that matters damber...i tried the code as it is and it worked...

-DNG
 
Really ?

I've just run it and it doesn't work... the point I was making is that you are mixing server side code ( project_link=trim(request.form("link")) ) and client side code ( window.open(project_link,etc...) - how would the javascript know about the VBScript variable project_link ?

Hence the inline response write of the variable contents into the javascript code.

If you can get what you posted to work as is, I'd like to know how ! :)

Things changed in the code I provided:
Code:
<%
 [COLOR=red]dim sLink[/color]
 sLink = trim(request.form("link"))
%>
<script [COLOR=red]type="text/Javascript"[/color]>
window.open([COLOR=red]"<%=sLink%>"[/color], null, "height=500, width=760, status=yes, toolbar=no,menubar=no, location=no");
</script>

A smile is worth a thousand kind words. So smile, it's easy! :)
 
i agree...i was wrong...i tried something else and thought that worked :)

-DNG
 
Not like you to miss something like that DNG..? You must be having a bad day ? :-(

A smile is worth a thousand kind words. So smile, it's easy! :)
 
it happens sometimes to everyone :)

i was running a cached page and thinking i made the changes and it worked ;)

-DNG
 
Great - it works fine now! Thanks to both of you.

This morning, I couldn't see how DNG's suggestion would work since I had already put the code into one line a couple of days ago, with no effect.

I understand about the cache; we all have those lapses--had a similar problem this morning when trying Damber's code with no succcess.

Turns out I was forgetting that my popup blocker was functioning well, blocking the new window. Using Ctrl-click solved that problem.

Thanks, also, for your explanation to DNG, Damber, I learned from it. Haven't worked with ASP recently, more likely to use PhP, but also hadn't combined it with javascript.

GOT (Instead of 'grandfather of ten' it now had to be 'grandfather often' since 2 more have arrived since I registered and number 13 is on the way!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top