- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这可能是常识,但我似乎无法找到有关该问题的任何信息。这是一些背景知识:
我有一些页面使用了 Bootstrap 的标签系统。在这些页面的 $(document).ready()
函数中是一些基于 URL 中的散列激活选项卡的基本代码,以及附加到选项卡显示功能的短函数使用 location.replace
更改位置的散列。结果是你可以链接到一个特定的标签,刷新页面也会让你保持在当前选项卡上。这适用于除 Internet Explorer 之外的所有内容。
在 Internet Explorer 中(我一直在使用 IE9 进行测试),在 IE 识别位置哈希已更改之前似乎有延迟(大约 10-15 秒)。在地址栏中手动输入哈希并加载页面时会发生类似的事情——需要几次刷新才能识别。单击其中嵌入哈希的链接似乎可以正常加载。
我假设这是某种故障。我想我可以将 cookie 附加到处理持续选项卡状态的代码,但有没有其他人找到处理此问题的更优雅的方法?
最佳答案
我不熟悉或不知道 Bootstrap 的标签系统有任何延迟,您可能想确认问题不是由您的特定使用或计算机引起的。我无法在我熟悉的任何浏览器上使用 jQuery hashchange 插件产生任何延迟。
至于处理基于哈希的导航的其他方法,我编写了以下内容以使用 jQuery hashchange 插件更改 hashchange 事件的内容/页面;主要是为了干净地支持带有哈希的后退/前进/链接。我下面是我正在使用的 trim 版本。
该示例提供了一个 anchor 链接并使用 onclick 事件生成。首选使用 onclick 事件,因为如果用户单击当前事件的选项卡,页面仍会重新加载。跟踪页面加载时间以确保页面不会在 100 毫秒内加载两次。
jQuery 哈希插件:http://benalman.com/projects/jquery-hashchange-plugin/
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://benalman.com/code/projects/jquery-hashchange/jquery.ba-hashchange.js"></script>
<script>
var hashUris = [];
var tabSet;
var actPage = '';
// bare tab array (use to populate tab html and hash array)
tabSet = [{hash: 'page1', pageId:1, id: 1}, {hash: 'page10', pageId:10, id:2 }, {hash: 'page20' , pageId: 20, id: 3}];
// handles the hash events
$(function() {
// loop all tab array, add items to hash array, determine primary page and active page
$.each(tabSet, function(i, tab) {
// using tabIndex to prevent looping hash array later
tab.tabIndex = i;
// first tab is primary by default
if (typeof priTabId == 'undefined') priTabId = tab.id;
// add tabs/page info to hash array
hashUris.push({hash: tab.hash, pageId: tab.pageId, tabIndex: i, tabId: tab.id, priActive: priTabId == tab.id});
// initial page to be loaded
if (priTabId == tab.id) priTabIndex = i;
// current hash
if (location.hash && '#'+tab.hash == location.hash) activeTabIndex = i;
});
if (!location.hash && !actPage && typeof priTabIndex != 'undefined') {
// page load, load primary tab
loadTabPage(priTabIndex);
} else if (location.hash && !actPage && typeof activeTabIndex != 'undefined') {
// page refresh
loadTabPage(activeTabIndex);
}
$(window).hashchange( function(){
if (location.hash) {
$.each(hashUris, function(index, hashUri) {
if ('#'+hashUri.hash == location.hash && actPage != hashUri.pageId + '#' + hashUri.hash) {
// found matching tab/page
loadTabPage(hashUri.tabIndex);
}
});
} else if (actPage) {
// navigated to empty space, attempt to find a primary active page
$.each(hashUris, function(index, hashUri) {
if (hashUri.priActive) loadTabPage(hashUri.tabIndex);
});
}
});
});
function loadTabPage(tabIndex) {
if (typeof tabSet[tabIndex] == 'undefined') return;
// track when the page was loaded
lastLoad = tabSet[tabIndex].lastLoad;
tabSet[tabIndex].lastLoad = new Date().getTime();
// load only once in 1ms-100ms
if (tabSet[tabIndex].lastLoad - lastLoad < 100) return;
// load page content/do actions here
alert(tabSet[tabIndex].pageId);
//$("#content").load('?pageId='+tabSet[tabIndex].pageId);
// active page checked against hash during hashchange
actPage = tabSet[tabIndex].pageId + '#' + tabSet[tabIndex].hash;
};
// user code to create tabs
$(function() {
// use tabs array to display some tabs
// this depends on the above code to set .tabIndex on the tabSet array
tabsObj = $('<div/>');
$.each(tabSet, function(i, tab) {
if (!tab.hash) return true;
tmpObj = $('<span>'+tab.hash+'</span>');
tmpObj.data('tabIndex', tab.tabIndex);
// use an onclick event to change the page
tmpObj.bind('click', function(e) {
if (typeof $(this).data('tabIndex') == 'undefined' || typeof tabSet[$(this).data('tabIndex')] == 'undefined') return;
// load page directly if active hash, otherwise change to clicked hash
if ('#'+tabSet[$(this).data('tabIndex')].hash == location.hash) {
loadTabPage($(this).data('tabIndex'));
} else {
location.hash = tabSet[$(this).data('tabIndex')].hash;
}
e.stopPropagation();
return false;
});
tmpObj.appendTo(tabsObj);
delete tmpObj;
});
tabsObj.appendTo($("#tabs"));
delete tabsObj;
});
</script>
<div id="tabs"><a href="#page1" >Link to Hash</a></div>
<div id="content"></div>
关于javascript - 延迟 Internet Explorer 注意到 location.hash 的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10264911/
我正在尝试使用 Rust 的 std::hash 函数: use std::hash::{hash, Hash, SipHasher}; #[test] fn hash_test() { pr
我有以下内容 friends = [{ name: "Jack", attr1:"def", attr2:"def" }, { name: "Jill", attr1:"def", attr2:"de
我有以下数组: names = [ {"Adriana"=>{:gender=>"female", :nationality=>"danish"}}, {"Adriane"=>{:gender=>"f
我有一个哈希的 Perl 哈希......大约 11 或 12 个元素深。请原谅我没有重复下面的结构! 一些级别有固定的标签,例如'NAMES' , 'AGES'或类似的,因此访问这些级别很好,因为我
我试图派生一个描述结构化值的Graphviz文件。这是出于诊断目的,因此我希望我的图形尽可能接近地反射(reflect)内存中的实际结构。我正在使用下面的方法将值映射到Graphviz顶点,以便当一个
我正在尝试获取在 xlm 中传递的事件日志条目,将它们转换为散列,然后存储到数据库中。 我目前正在使用 XmlSimple gem 将 xml 输入转换为散列。 测试样本输入: require 'xm
对于 Ruby 中的 Hash,reject! 和 reject 与 delete_if 有何不同?谁能用简单的代码片段解释它们之间的区别? 最佳答案 由于其他答案指的是 Array#delete_i
我正在尝试处理我使用 Data::Dumper 输出的 perl 数据结构 $VAR1 = 'GAHD'; $VAR2 = [ { 'COUNTRY' => 'US',
无法使用来自辅助进程的现有 rte Hash: h = rte_hash_find_existing("some_hash"); if (h) { // this will w
我有一个散列的散列,其中第一个键是一个字符串,第二个键是一个整数。我试图在散列的散列中获得最低的第二个键。这是我的哈希。 %HoH = ( flintstones => { 8
如何从一系列数组中生成哈希中的哈希?我需要从这里开始: my @data = /one two three/; my $value = 13: 为此: $hoh = { 'one' => { 'two
我有这个配置文件 dbUser=customer dbPass=passwrd dbSid=customer.shadow passwdFile=/production/etc-user tmpUse
我想实现一种thing,可以唯一标识,除此之外,它不包含其他字段。它有点像 ruby 中的 BasicObject 或 java 中的 Object。 我添加了一个 PartialEq 特征。 s
我正在尝试使用以下键存储二维哈希: 维度 1 = 数字但不连续 维度 2 = 字符串(如 :id 和 :value) 当元素未初始化时会出现问题。 memory = Hash.new(Hash.new
我目前正在学习 Michael Hartl 的 Ruby on Rails 教程 不理解在 section 4.4.1 中找到的此语句的含义: Hashes, in contrast, are dif
我很乐意通过更短的表达式访问多维哈希数组的任何元素 h = {a: {b: 'c'}} # default way p h[:a][:b] # => "c" # a nicer way p h[:a,
我想在编写 flutter channel beta 后运行 flutter web 它回复:Can't load kernel binary:Invalid SDK hash,你知道如何解决这个问题
我最近正在研究 Amazon 提供的新 NoSQL 服务,更具体地说是 DynamoDB。 亚马逊说你应该避免使用不均匀分布的键作为主键,即主键应该越独特越好。我可以认为这是最好的情况下每个项目都有唯
我的游戏中有很多哈希值,例如 HMSET('hash1', 'level', 25, 'connected', 2) HMSET('hash2', 'level', 50, 'connected',
我必须翻译这句话:'Susspected overpass-the-hash attack (Kerberos)' 我发现了这篇关于立交桥哈希的文章:https://blog.stealthbits.
我是一名优秀的程序员,十分优秀!