动态Href无法使用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的路径时,它确实有效,但当我尝试使用href中的函数时,它不起作用。有什么建议吗?这是该问题的屏幕记录,链接。

而不是

href="javascript:getLastLocation()"

进行

onclick="window.location = getLastLocation()"

最新更新