onclick="javascript:history.go(-1)";无法在 Chrome 中工作 [英] onclick="javascript:history.go(-1)" not working in Chrome

查看:28
本文介绍了onclick="javascript:history.go(-1)";无法在 Chrome 中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码在 FF 中工作正常,它会将用户带回上一页,但在 Chrome 中则不然:

This code works fine in FF, it takes the user back to the previous page, but not in Chrome:

<a href="www.mypage.com" onclick="javascript:history.go(-1)"> Link </a>

解决方法是什么?

推荐答案

你应该使用 window.history 并返回一个 false 以便 href 不被导航浏览器(默认行为).

You should use window.history and return a false so that the href is not navigated by the browser ( the default behavior ).

<a href="www.mypage.com" onclick="window.history.go(-1); return false;"> Link </a>

这篇关于onclick="javascript:history.go(-1)";无法在 Chrome 中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆