【问题标题】:Using the same redirect function in two different pages在两个不同的页面中使用相同的重定向功能
【发布时间】:2023-01-09 20:53:47
【问题描述】:

好的,所以我的索引页面有这个带有登录选项的标题,我使用这两个函数选择了按钮

function getHeaderButtons() {
    const showHidePopUp = document.querySelector('.titleAndMenuIcon > img')
    const windowPopUP = document.querySelector('.mobilePopUp')
    const main = document.querySelector('main')
    

    showHidePopUp.addEventListener('click', () => {
        windowPopUP.classList.toggle('moveUpAndDown')
        console.log('ok')
        
    })
}
function getLoginAndSubscribeButtons() {
    const login = document.querySelector('.mobilePopUp__login')
    const subscribe = document.querySelector('.mobilePopUp__subscribe')

    login.addEventListener('click', () => {
        window.location.href = "./src/pages/loginPage.html"
    })

    subscribe.addEventListener('click', () => {
        window.location.href = './src/pages/subscribePage.html'
    })
}

这些在我的主页上工作得很好,当我将这些功能导出到其他页面时,问题就开始了(所以我不必重新重写它们)

这是enter image description here显示的消息

我想要一种方式,即使在订阅页面中单击订阅按钮,它也会再次重定向到订阅页面。有没有办法做到这一点?

我试图查看代表主页的通配符,以便它始终可以引用我的索引页

【问题讨论】:

    标签: javascript html


    【解决方案1】:

    使用绝对路径

    /src/pages/loginPage.html
    

    【讨论】:

      猜你喜欢
      • 2014-06-24
      • 2010-10-22
      • 1970-01-01
      • 2011-08-08
      • 1970-01-01
      • 2022-11-19
      • 2021-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多