动态 Href 无法使用 Javascript

Dynamic Href not working using Javascript

function setLastLocation() {
        var lastLocation = window.location.pathname
        localStorage.setItem('lastLocation', lastLocation)
      }

一起
function getLastLocation() {
        let lastLocation = localStorage.getItem('lastLocation')
        lastLocation = `../..${lastLocation}`
        return lastLocation
      }

<a href="javascript:getLastLocation()" class="close item item-1">
    <i class="fas fa-arrow-left fa-2x" style="color: white"></i>
</a>

正在尝试为我的 cordova 应用程序制作一个后退按钮以导航到上一页,但我的 href 设置没有按我预期的方式工作。有两种方法可以访问我的应用程序的书籍,通过单击搜索结果中的链接或通过 UI 导航手动访问书籍。根据用户获取书籍的方式,我希望 href 相应地重定向。 setLastLocation() 设置在指向内容的所有链接上,而 getLastLocation() 设置在实际内容的后退按钮上。当我按字面意义键入 href 的路径 (../../tracts.html) 时,它有效,但当我尝试使用 href 中的函数时,它不起作用。有什么建议么?这是问题的屏幕录像,link

而不是

href="javascript:getLastLocation()"

onclick="window.location = getLastLocation()"