[英]Javascript named jump to anchor
我正在嘗試創建一個刷新頁面的函數(並重置測驗)並跳轉到具有按鈕的錨點。
這適用於chrome和firefox但在IE中它只刷新到第一個命名錨點。
我的代碼:
function resetQuiz(showConfirm)
{
if(showConfirm)
if(!confirm("Are you sure you want to reset your answers and start from the beginning?"))
return false;
window.location.reload(); //this works for chrome and firefox
window.location.hash="mercquiz"; //tried this for IE. doesnt work
}
您可能在哈希有機會更新之前重新加載頁面。
試試這個:
var loc = window.location.toString();
window.location = loc.substring(0, loc.indexOf("#")) + "#mercquiz";
window.location.reload();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.