Forum Moderators: open

Message Too Old, No Replies

Redirecting to another html page via VBScript

Can it be done?

         

ritch_b

1:35 pm on Jun 19, 2003 (gmt 0)

10+ Year Member



I need to create a simple html page that, via use of VBScript, redirects the user to another page that I specify.

Acheiving this using the META HTTP-EQUIV=Refresh tag would be preferable, but I need to use VBScript to identify the computer's network name and append this to the end of the URL string, e.g.

The PC named "NETWORKPC1" is redirected to page.htm?networkpc1

The PC named "NETWORKEDLAPTOP" is redirected to page.htm?networkedlaptop

Identifying the computer name & appending this to the URL isn't a problem - the redirect itself is.

Any help would be appreciated!

R.

korkus2000

1:41 pm on Jun 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you using ASP or just client side VBScript?

ritch_b

1:44 pm on Jun 19, 2003 (gmt 0)

10+ Year Member



All client side - has to go inside a static html page unfortunately.

R.

mattur

2:03 pm on Jun 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AFAIK you can't do this in vbscript in IE... you can do it client side with wsh, but I don't think IE will allow the object call in a web page.

Server side you would:

1. pick up the user's IP address using REMOTE_ADDR from the server variables.
2. Resolve the IP to a DNS name, and parse out just the bit you want.
3. Build the url string to redirect to, and redirect to it (assuming only one IP address per client) ;)

Can't you just redirect the static page to a dynamic page?

ritch_b

2:10 pm on Jun 19, 2003 (gmt 0)

10+ Year Member



Can't you just redirect the static page to a dynamic page?

No can do unfortunately - the VBScript has to be used to identify the computer name which needs to be appended to the static url.

This isn't a problem if I'm creating a basic link, but having it as a redirect is.

The page needs to be self contained as no internet connection will be present - I don't want to hard code the computer name as there could ultimately be around 20000 names to chose from, with regular additions and deletions.

I know you can do lots of (dodgy) things in IE with VBScript (like pulling the computer name?!?) but can't find reference to any redirect-esque functionality.

R.

ritch_b

2:18 pm on Jun 19, 2003 (gmt 0)

10+ Year Member



Sorted!

The original idea I had wasn't overly incorrect - I'd just messed up with the quote marks. Taking a fresh look produced the following :

<script language="VBScript">
<!--
Set objNetwork = CreateObject("WScript.Network")
document.write(" <META HTTP-EQUIV=Refresh CONTENT=""0;URL=page2.htm?" + objNetwork.ComputerName + """>")
//-->
</script>

The page does just what I needed - redirects to page2.htm but appends the computer name to the URL like so :

http://www.domain.com/page2.htm?COMPUTERNAME

I'm still not enamoured with VBScript in IE, but it does what I needed so I'll turn a blind eye!

Cheers Guys!

R.

mattur

2:22 pm on Jun 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep this will work providing the user has the appropiate security settings. Doesn't work on my IE but then I'm security paranoid ;) Glad you got it sorted

ritch_b

2:32 pm on Jun 19, 2003 (gmt 0)

10+ Year Member



All the systems using it will be set to minimal (or rather, no) security - the pages won't be available across the net!

I'm sure that if I looked into VBScript, there'd be some very dodgy things one could do with it...just another reason to use Mozilla or Opera I s'pose!

R.

Iguana

2:42 pm on Jun 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd love to know how you get the machine name in client side VBScript - I know it's easy on the server side.

Am I missing something or can you not just call document.location="pagename.html?NETPC1" on the client (maybe in a page onload event)?

ritch_b

2:58 pm on Jun 19, 2003 (gmt 0)

10+ Year Member



If it's client side, you can pull the computer name easily - plonk this into a html page :

<script language="VBScript">
<!--
Set objNetwork = CreateObject("WScript.Network")
document.write("computer name is=" + objNetwork.ComputerName + "")
//-->
</script>

Requires low security in IE though.

I'd tried a few ways to do the redirect, but all fell over when it came to appending the computer name apart - my experience of VBScript is non-existant, so there are undoubtedly other ways to acheive the same effect!

R.