• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

Using Location object with VBScript

I am trying to use the Location object to go from one ASP page to another and get a VBScript runtime error: Variable is undefined: Location.

Here's the code I'm using;

<% Location.Href="test.asp" %>

Is it possible to use the Location object with VBScript?  Every example I've seen is using JavaScript.  If you can't use it from VBScript, then how do you jump to another page?  I can't use the Response.Redirect because I've already displayed HTML to the browser.  The Response.Redirect has to execute before any HTML code.
0
tonylclayton
Asked:
tonylclayton
  • 3
  • 2
  • 2
1 Solution
 
clockwatcherCommented:
Location is a client-side object of the browser.  It has nothing to do with server-side code.

There's very little point in using vbscript as only IE understands it-- but if you really want to, you simply have to move it client-side.

<script language=vbscript>
location.href = "http://www.yahoo.com"
</script>
0
 
clockwatcherCommented:
If you really want to use response.redirect after writing content, you can buffer your response.

<%
response.buffer = true
%>
<html>
<body>
Whatever
</body>
</html>
<%
response.redirect "http://www.yahoo.com"
%>
0
 
MarineCommented:

right after this line put that line below <%<@language="vbscript"%>
response.buffer = true ]

then you can use response.redirect ("url.asp")
anywhere in your code
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
tonylclaytonAuthor Commented:
Thanks!  But if you don't use the location.href to move to another page, how do you do it?
0
 
MarineCommented:
the response.redirect will take you to another page. Desn't it ?
you must set response.buffer = true if you want to use it before outputing any html.
0
 
clockwatcherCommented:
I'm not sure what you're asking?  Do you want to move to another page after you've displayed some content or do you actually want to do redirect.

Server-side, the only way to move to another page is with a redirect.  Basically, you're telling the client that the page they've requested is no longer there and that it's really somewhere else.  That's why you have to buffer the content or send it out before sending any html-- it's a header value.

Client-side there are a couple of ways to redirect.

You can use a meta tag:

  <meta http-equiv="refresh" content="5;URL=http://www.yahoo.com">

You can use inline javascript

<html>
<body>
It is now: <%=now%>
<script language="javascript">
  location.href="http://www.yahoo.com"
</script>
</body>
</html>

You can use a function:
<html>
<head>
<script language="javascript">
function move() {
  location.href = "http://www.yahoo.com";
}
</script>
</head>
<body onload="setTimeout('move()', 5000">
Whatever
</body>
</html>
0
 
tonylclaytonAuthor Commented:
I actually want to move to another page after I've displayed some content.  I did not know about the Response.Buffer statement.  I tried that and it worked.

Thanks!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now