javascript - IE11 无法使用 document.location.href 或 $(location).attr ("href"获取当前 URL

标签 javascript jquery html ajax

我必须添加一个 anchor 标记,单击该标记时会重新加载当前页面( anchor 标记包含当前网址)

document.getElementById('clickhere').innerHTML='<div>Something went Wrong! <a href=""'+$(location).attr("href")+'>Click here to reload</a> </div>';

当我点击 Chrome 中的 anchor 标记时,页面加载正常。根据屏幕截图,当我将鼠标悬停在链接上时,它会显示完整的 URL。在/private 之后我可以看到 URL 的其他部分。

enter image description here

下面的屏幕截图是我在 IE11 中执行该页面时的。如果我检查,/private 之后的部分不存在。

enter image description here

我不明白为什么会出现这种差异。我已在 Jquery AJAX 成功部分添加了此代码。还尝试使用 Javascript 的 document.location.href 但仍然存在同样的问题。

最佳答案

你可以尝试一下:

windows.location.href

document.getElementById('clickhere').innerHTML='<div>Something went Wrong! <a href="' + window.location.href + '">Click here to reload</a> </div>';
<div id='clickhere'></div>

关于javascript - IE11 无法使用 document.location.href 或 $(location).attr ("href"获取当前 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47466272/

相关文章:

javascript - 从主干模板上的集合中获取数据

javascript - document.getElementById 在 Firefox 中返回元素,但在 Chrome 中不返回元素

javascript - 切换标签时加载内容

javascript - 在全屏覆盖中打印文本?

javascript - Jquery 手机 1.8.2 : trapping scrollstop event

javascript - 维护 Vue 页面之间的状态

html - 无法重叠 DIV

javascript - 如何使用 JavaScript 写入 html?

javascript - 为什么 Math.pow() (有时)在 JavaScript 中不等于 **?

jquery - Angular2 可滚动内容