user1658567
user1658567

Reputation: 201

History.go(-1) not working in IE

I have a go back button and i have used the following piece of code in my aspx page

<input type="button" runat="server" value="Back" onclick="Javascript:history.go(-1); return=false;" />

The prob is its working fine in Firefox but when i am trying it in IE its not working. Can someone share their Idea.

Update

By mistake I write return=false; the actually code is:

<input type="button" runat="server" value="Back" onclick="Javascript:history.go(-1); return false;" /> and still not working.

Upvotes: 3

Views: 6511

Answers (2)

T.J. Crowder
T.J. Crowder

Reputation: 1074495

Your quoted code shouldn't be working on any browser, it has a syntax error (return=false). With minimal changes:

<input type="button" runat="server" value="Back" onclick="history.go(-1); return false;" />

Also note that you don't need (and shouldn't have) any Javascript: prefix on any onXyz attribute. The code in onXyz attributes is always JavaScript, and in fact that prefix (in that situation) doesn't trigger JavaScript, it creates a label that's never used. You use the javascript: pseudo-protocol in places where a link is expected, such as the href attribute on an a element.

Side note: I haven't done any ASP.Net in a long time, I'm not at all sure it makes sense to have runat=server and onclick on the same input... If you want a client-side "Back" button, remove runat=server.

Upvotes: 7

androbin
androbin

Reputation: 1759

Use <a href="Javascript:history.go(-1); return false;">Back</a> or <input type="button" runat="server" value="Back" onclick="history.go(-1); return false;" />

After any on... events you need no javascript, you need it only at href. And at the return you need no =.

Upvotes: 1

Related Questions