问题描述
我无法在Safari中使用 window.location.hash = location.hash
。
我正在使用JavaScript将我的页面内容用可滚动的DIV进行封装,放置在我的网页导航栏下方。由于滚动条的位置在javascript运行时被重置,因此我将丢失URL设置的原始哈希位置。我需要重新提示散列位置而不使用JavaScript重新加载页面,所以我使用 window.location.hash = location.hash
。它适用于IE8,Firefox和Opera,但在Safari中无法使用。 (我也会假设Chrome,但我没有检查)。任何建议?
提示:我喜欢jQuery。 / div> Webkit有两个特点,可以防止 这段代码解决了我的问题:(使用jQuery)。 I can't get I'm using javascript to wrap the contents of my page with a scrollable DIV, placed below the navigation bar in my webpage. Since the scrollbar's location gets reset when the javascript runs, I'm losing the original hash location that the URL set. I need to re-cue the hash location without reloading the page using javascript, so I'm using Hint: I like jQuery. Webkit has two oddities that prevent This code solved my problem: (using jQuery). 这篇关于" window.location.hash = location.hash"在Webkit(Safari和Chrome)中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! window.location.hash = location.hash
正常工作。
window.location.href
而不是 window.location.hash
(与所有其他浏览器一样)。奇怪的是, webkit
仍然可以使用 location.hash $ c读取URL的
hash
标签
位置
必须在浏览器前两次设置到同一位置到新的位置。错误报告。
$ (document.ready)(function(){
gotoHASH()
};
函数gotoHASH(){
if(location.hash){
if($ .browser.webkit == false){
window.location.hash = location.hash;
} else {
window.location.href = location.hash;
}
};
window.location.hash = location.hash
to work in Safari.window.location.hash = location.hash
. It works in IE8, Firefox, and Opera, but it doesn't work in Safari. (I'll assume Chrome, too, but I haven't check). Any suggestions?window.location.hash = location.hash
from working normally.window.location.href
instead of window.location.hash
(like all the other browsers do). Curiously, webkit
can still read the URL's hash
tag using location.hash
location
has to be set to the same location twice before the browser will go to the new location. Bug report here.$(document).ready(function() {
gotoHASH()
};
function gotoHASH() {
if (location.hash) {
if ( $.browser.webkit == false ) {
window.location.hash = location.hash;
} else {
window.location.href = location.hash;
}
}
};