javascript - 链接不记得之前的页面
问题描述
我在 CSS 网格中工作。我有一个专栏,我在其中添加了背景图片。link-x
我已使用以下 javascript将该背景图像制作成超链接 ( )。
问题不在以下。如果我执行以下操作:
我去https://my-site.com
并点击超链接link-x
。我在浏览器中单击“返回”,这意味着我应该返回到https://my-site.com
。但是当我单击返回时,我将进入我的浏览器起始页。
浏览器似乎不知道我在我的网站上访问过的上一页。
有谁知道这是否有解决方案?
$('.sbp-item1').click(function(e) {
window.location.replace("https://my-site.com/link-x");
});
.sbp-item1 {
grid-row: 1 / 3;
grid-column: 1/9;
height: 520px;
display: flex;
justify-content: flex-end;
flex-direction: column;
background-image: url("/Static/Cms/d1bd45c5-f39e-4b8f-8c47-f7fe5497b1a4.jpg");
cursor: pointer;
}
<div class="sbp-wrapper">
<a class="sbp-item1 bg-img" href="https://my-site.com/link-x"></a>
</div>
解决方案
的全部意义replace
在于它替换了浏览器历史记录中的当前页面。
location
如果要正常导航,请将新 URL 分配给:
window.location = "https://my-site.com/link-x";
推荐阅读
- python - 使用字典的基本异常处理
- firebase - 无法在 Firebase 中观察节点(未接收更新)
- go - 例行检查频道范围
- javascript - How to close modal and return value from flatlist when click on item in react native?
- c++ - 深拷贝具有自引用指针的类
- spring-boot - How to deal with ContraintViolationException and other Exceptions
- python - 为什么 select_dtypes 在这种情况下在熊猫中不起作用
- java - 如何提高内部其他 REST 调用的 REST 调用的性能
- qt - 如何在 Qt Creator 中将 Qdialog 设置为具有尽可能小的固定高度和扩展宽度?
- java - 为什么对象数组中的元素没有更新?