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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert From ASP to Javascript

Status
Not open for further replies.

Krus1972

Programmer
Mar 18, 2004
145
US
Hello,

I am an ASP programmer and know only a little Javascript. Can someone convert the following ASP code to Javascript? Basically the script requests the variable "q" from the query string and if its = "" then the browser redirects to a URL that is specified.


<% If request ("q") = "" Then
response.redirect (" End If
%>

Thank you for any help
 
Hi

You can not. The [tt]response.redirect[/tt] returns HTTP 302 response code. Client-side scripting languages can not set it.

The closest JavaScript alternative would be this :
Code:
if (location.search.match(/(^|[?&;])q=([&;]|$)/)) location.href='[URL unfurl="true"]http://example.com/'[/URL]

Feherke.
 
Hello,

I don't care about the 302 response code. The only thing need the javascript to do is:

1. Request "q" from the querystring
2. Check to see if it's empty
3. Then send the visiotr to another URL that I specify in the script.

I don't care about the 302.

Thanks for any help.
 
Can you post an example URL from the browser address bar and also do a Response.Write(q) when (q = "") and when q <> "" and then post the two results?
 
feherke,
First, I'm wondering why Krus1972 doesn't use asp to do the redirect (if it's an asp page).

How would it help me? I'd look at the result and see if I could come up with an alternate route besides what you posted using a combo of asp and js.
 
The title for the question is "Convert From ASP to Javascript" which seems to answer the discussion. feherke's answer seems to be perfect for the question as asked.

If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top