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

Redirecting the browser to another URL

Status
Not open for further replies.

ChuckG

MIS
Feb 28, 2001
211
US
This is my first project with VBScript and I'm running into a problem. I need to change the browser's document from the ASP page that it's currently running on to one defined by a if/then statement (results inserted into a variable).

But trying to use (URL1 is the variable with the new document name)

Window.document = URL1

Comes back with an Object required error.

Any tips from the master's out there?

Thanks in advance.

Chuck
 
Try
window.location = url1

that is definitely the javascript, but the vbscript may be

window.document.location = url1

Play around with the location property -- that's your key.

If you're using server side script (ASP), then you can use response.redirect(url1) -- but this will not work client-side.

:)
Paul Prewett
penny.gif
penny.gif
 
Thanks. I tried the window.document.location = url1 and still get the object required: window
error.

This is being used on a ASP page (part of it is pulling data from a database. I'll post a copy of my current code in this message. If I put the response.redirect(url1) in it gives me this error:
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.

Even though there is nothing being sent to the page.

<html>

<head>
<title>Home Page</title>
</head>

<body>

<p><%@ LANGUAGE=&quot;VBSCRIPT&quot; %> <%
'Declaring variables
Dim cust_id1
Dim act_flags1
Dim url1
Dim objConn
Dim objRS
Dim strSQL

'Setting Variables
Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
objConn.ConnectionString = &quot;DSN=inv_data&quot;

'Assigning Form results to variable
cust_id1 = CStr (Request (&quot;cust_id&quot;))

'Open a connection
objConn.Open

'defining SQL statement and retrieving data
strSQL = &quot;SELECT ACT_FLAGS FROM billmstr WHERE cust_id = '&quot; + cust_id1 +&quot;'&quot;
ObjRS.Open strSQL, objConn

act_flags1 = objRS(&quot;ACT_FLAGS&quot;)
act_flags1 = Mid(act_flags1, 5, 1)


'Determine if flag is on
if act_flags1 = &quot;Y&quot; then
url1 = &quot;../&quot; + cust_id1
else
url1 = &quot;reject.htm&quot;
End If


'Close the Recordset object
objRS.Close

'Delete the Recordset Object
Set objRS = Nothing


'Close the Connection object
objConn.Close

'Delete the Connection Object
Set objConn = Nothing

%></p>
</body>
</html>
 
To avoid that error -- the http headers thing -- put this code at the top of your page within the server script tags:

<%response.buffer=true%>

That will clear the problem up --
penny.gif
penny.gif
 
You will also need
<%response.clear%> to clear out the buffer.
&quot;If buffering is enabled, all output is allowed to accumulate in the buffer until it is either cleared or flushed (with the Clear and Flush methods respectively) or the script ends.&quot;

 
I must not be doing something right, I continue to get that error about the http header being already written to.

It seems like such a chore just to redirect a page. lol

Even after putting the <%response.buffer=true%> at the beginning of the vbscript and the <%response.clear%>

Would the fact that I'm pulling data from a table be affecting this at all?
 
Did you put the <%Response.buffer = true%> BEFORE ANY HTML was written. If not then it was probably too late.
Code:
<%Response.buffer = true%> 
<html>

<head>
<title>Home Page</title>
</head>
 
John,

Thank you sir. That corrected the issue. And the page is working perfectly. Now I just have to figure out one other little problem regarding why I can't point a DSN to a DBC residing on another internal server (Internal NT Domain).

But this helped out a ton Thanks for helping a very novice ASP coder.

Chuck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top