繁体   English   中英

Javascript命名为jump to anchor

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM