Javascript asp 按钮和历史记录回到客户端点击

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1922081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 21:55:03  来源:igfitidea点击:

asp button and history back onclientclick

javascriptasp.netclientscript

提问by Hyman Black

hi I have an asp button which is created using the following code:

嗨,我有一个使用以下代码创建的 asp 按钮:

<asp:Button ID="btnBack" OnClientClick='javascript:history.back()' runat="server" Text="back">
</asp:Button>

However, now the javascript doesn't work to go a history back. On the other hand, if I make an alert() it works...why. Why is it not working to go a history back?

但是,现在 javascript 无法追溯历史。另一方面,如果我发出警报()它会起作用......为什么。为什么要追溯历史是行不通的?

回答by TStamper

Try with return falseat end:

尝试在最后返回 false

 <asp:button id="btnBack" runat="server" text="Back" 
OnClientClick="JavaScript: window.history.back(1); return false;"></asp:button>

回答by graphicdivine

Try:

尝试:

parent.history.back();

Or

或者

history.go(-1)

回答by Rafe

Had the same problem in DevExpress project. Using ASPxButton without initializing the property "AutoPostBack" will result in redirect to self page before any client-side function call. Try AutoPostBack="false"for the button.

在 DevExpress 项目中遇到了同样的问题。在没有初始化属性“AutoPostBack”的情况下使用 ASPxButton 将导致在任何客户端函数调用之前重定向到自身页面。试试AutoPostBack="false"按钮。