gpt4 book ai didi

javascript - 从页面重定向中排除 id (jquery)

转载 作者:行者123 更新时间:2023-12-03 11:17:46 24 4
gpt4 key购买 nike

我刚刚在 stackoverflow 上获得了一些关于定义 ID 属性(例如 /name)的帮助。经过一番工作后,我的单页网站可以使用自定义 ID。但!这是我的问题:

当访问者第一次访问索引文件时,我希望浏览器像这样重定向:

example.com -> 1500 后重定向 -> example.com/#/all/

但是,由于它是一个单页网站,因此我的所有其他 div(当 /all/ 处于事件状态时隐藏)都位于同一页面上,因此具有相同的重定向属性。因此,如果用户直接访问 ID (example.com/#/work/),浏览器将在 1500 后重定向到 #/all/。因此无法直接链接到某些项目。另外,我有多个以 /work/ 开头的 id。

这就是我现在正在做的事情

window.setTimeout(function() {

window.location.href = '#/all/'; // redirect the visitor when loading the index for the first time
}, 1500);
$('#/work/...','#/about/').on('ready', function () { // Select ALL that has the id "#/about/", and/or all that starts with the id "#/work/"
window.location = ""; // No redirect, just load the page with the targeted id active
});

最佳答案

仅当尚未定义哈希时才运行重定向..

if (window.location.hash.length === 0){
window.setTimeout(function() {
window.location.hash = '/all/'; // redirect the visitor when loading the index for the first time
}, 1500);
}

关于javascript - 从页面重定向中排除 id (jquery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27260118/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com