In vbscript, how do you tell the browser to go back to the previous page?
Printable View
In vbscript, how do you tell the browser to go back to the previous page?
No javascript?
If you know the answer in Javascript, that'll do...
javascript:history.go(-1);
Actually, that's no good for me. I am doing this project in VB.NET and with VB Script.
There doesn't seem to be a history object available to use... :confused:
Are you absolutely restricted to VBScript? That seems to be an odd choice because VBSCript would imply an IE-only environment, and IE supports javascript for that matter....
Try...
call window.history.back(1)
or
call window.history.back(-1)
Just play around with that, will ya?
I'm only restricted in as far as I know vb and I don't know java.
As for browser support, the script is being run at the server anyway so it shouldn't affect what browser the client uses, should it?
There is no Window object either...
Quote:
Originally Posted by simonm
No, client side scripting (namely javascript and vbscript) run on the end-user's machine. Even when a postback occurs on your aspx pages, it's done using javascript. (Ever took a look at the source of the output?)
It therefore becomes browser dependent, and if you use vbscript entirely for your client side scripting, then you are restricting your viewers to ONLY IE. And an FF user like me would just not visit.
Show your code, how are you trying to implement the back navigation thingimijig?
And take a look at this too:
http://support.microsoft.com/?kbid=205693
There should be a window object. I haven't tried this myself because the IE icon is not visible to me right now.
This site is not for the general public, only for business to business communcations.
And my script is all server side anyway.
And I have no code to go back...I have nothing...
I don't believe you. Actually, I think there's a slight misunderstanding. SHOW me what you have. You cannot have VBSCript Server side for asp.net.Quote:
Originally Posted by simonm
Quote:
And I have no code to go back...I have nothing...
What? :ehh:
All right, here's what I have:
When my page loads, I get the following error: "Name 'Window' is not declared."Code:<script runat="server">
Sub GoBack(sender As Object, e As System.EventArgs)
Window.History.GoBack(-1)
End Sub
</script>
When are you calling GoBack()?
From here:
Code:<asp:LinkButton id="lnkGoBack" OnClick="GoBack" runat="server">Back</asp:LinkButton>
You're making things complex for yourself. A simple:
would do for you!Code:<a href='#' onClick="javascript:history.go(-1);">Back</a>
But if you still want to use the <asp:LinkButton>, then...
Change this:
toCode:<asp:LinkButton id="lnkGoBack" OnClick="GoBack" runat="server">Back</asp:LinkButton>
this:
In the page load event,Code:<asp:LinkButton id="lnkGoBack" runat="server">Back</asp:LinkButton>
VB Code:
lnkGoBack.Attributes.Add("onClick","javascript:history.go(-1);")
That should be the correct syntax. I don't have the IDE open right now.
Thanks...but it's really causing problems for me using Javascript...
It must be possible in vbScript (or in VB.NET code), surely? :sick:
Actually, modifying your first example to vbScript wasn't difficult:
I guess the problem I was having was that the history object isn't available on the server. It had to be run on the client side...Code:<a href='#' onClick="history.go(-1)">Back</a>
In theory you could do it server-side like so:
It is redirecting you to the referring page (previous page). However I haven't tried it and I'm not sure what it'll do if the page has already done a postback (redirect back to itself?!?). Give it a try - you never know!Code:<script runat="server">
Sub GoBack(sender As Object, e As System.EventArgs)
Response.Redirect(Request.UrlReferrer.ToString())
End Sub
</script>
mendhak is right though if you are using ASP.NET you are using client-side JavaScript already just view the source of an ASP.NET generated page - it's all over the place! I do however try to develop pages so they still work with JavaScript disabled for accessibility reasons - it ain't easy let me tell you!
DJ
I was trying to explain that to you...Quote:
Originally Posted by simonm
Oh, and I hate to burst your bubble but that's javascript, I'm pretty sure. :wave:
Mendhak
My aspx page has the following property set:
Document.defaultClientScript = VBScript
so I would be suprised if it was javascript...
Indeed, if I change the code like this, it must surely be interpreted as vbScript, no?
Code:<a language =vbscript href='#' onClick="history.go(-1)">Back</a>
Hmm.. point there.
Confused me there, but it works, so it works! :afrog:
Yep, thanks. :wave: