use*_*779 9 javascript jquery redirect window.location browser-history
下面的代码效果很好.这是我的问题:窗口网址重定向,但原始网址未记录在我的浏览器历史记录中.
例如,如果我访问"http://example.com/page1",浏览器就会重定向到"http://example.com/test".但是,我需要访问的原始网址("http://example.com/page1")显示在我的浏览器历史记录中,以便我可以在其他功能中调用它.
在重定向之前,是否有访问原始网址以登录浏览器的历史记录?
<!-- script to enable age verification cookies and ensure people have age checked -->
<script type="text/javascript">
$(document).ready(function(){
if (window.location =="http://example.com/home") {//do nothing
} else {
window.location = "http://example.com/test";
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
我认为你需要的是window.location.href. 这会将先前的 URL 添加到浏览器历史记录中。