我有一个网络应用程序,其中有按钮,如果单击将转到特定历史记录。我听说只有IE支持history.go(url),但其他浏览器只接受数字值。就我而言,history.go() 将仅转到特定页面,例如http://localhost:54187/Products/Create
。即使用户导航到不同的页面,如果单击按钮,它仍然会转到历史记录的“创建”页面。我需要history.go,因为它相当于浏览器后退和前进。我无法使用 window.location 或 location.href,因为我的应用程序要求填充的数据仍然存在,正如history.go 所做的那样。如果用户总共加载了 26 个页面,我如何知道这 26 个页面中哪一个是创建页面,以便我可以使用 History.go(createIndex)? window.history.length 给出 26 但它不公开 url。
请帮助我如何解决我的问题。
JavaScript 和 HTML
<script type="text/javascript">
$(document).ready(function () {
$('#btnGoToCreate').click(function () {
var createIndex = //how to know what's the index of
//http://localhost:54187/Products/Create from window.history?
history.go(createIndex);
});
});
</script>
<input type="button" value="Go to Last Entry" id="btnGoToCreate" />
最佳答案
由于安全/隐私原因,您无法读取历史记录项目。您只能访问之前的 URL,可以使用以下方式读取该 URL:
document.referrer
您可以manipulate the browser history虽然如此,但这也不允许您转到用户历史记录中的特定页面。
关于javascript - History.go() 如何从 window.history 获取特定访问页面 URL 的索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15631888/