gpt4 book ai didi

html - 如何阻止直接访问html页面

转载 作者:行者123 更新时间:2023-12-01 11:07:19 24 4
gpt4 key购买 nike

我有一个子 html(模板)products.html,我用 JavaScript/jquery 函数 .load() 将它包含在我的 index.html 页面中

现在的问题是如果你输入它的 url 就可以直接访问 products.html,它单独给出一个非常难看的页面,所以我尝试使用 JS 函数 将任何试图访问它的人重定向到 index.html windows.location.这种方法的问题是,当我的模板加载到我的主页时,js 脚本会触发,并导致页面刷新。那么还有另一种方法可以解决这个问题吗!?

最佳答案

您可以定义一个变量,如 window.parentPage = true;在 index.html 文件中。

在 products.html 页面中进行如下检查:

if(!window.parentPage)
{
window.location.href = "YOUR REDIRECTION PAGE"
}

关于html - 如何阻止直接访问html页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43635621/

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