Jquery IE10从URL中去掉了标签
我们正在建立一个网站使用非常有限的CMS。我们唯一能做的就是操纵前端——使用模板,使用自定义css和js 由于我们无法“记忆”用户的选择,因此我们提出了一种解决方案,使用hashtags通过URL传递某些信息。这在Google Chrome和Mozilla Firefox浏览器上运行顺利,但IE10去掉了标签,jQuery无法为用户定制页面。下面是一些我们如何使用这个东西的例子: 表格: IE10行为(不良): 当我们拿起散列时我们会做什么: 问题:Jquery IE10从URL中去掉了标签,jquery,google-chrome,cross-browser,internet-explorer-10,Jquery,Google Chrome,Cross Browser,Internet Explorer 10,我们正在建立一个网站使用非常有限的CMS。我们唯一能做的就是操纵前端——使用模板,使用自定义css和js 由于我们无法“记忆”用户的选择,因此我们提出了一种解决方案,使用hashtags通过URL传递某些信息。这在Google Chrome和Mozilla Firefox浏览器上运行顺利,但IE10去掉了标签,jQuery无法为用户定制页面。下面是一些我们如何使用这个东西的例子: 表格: IE10行为(不良): 当我们拿起散列时我们会做什么: 问题: 为什么IE10要去掉标签(我真的很惊讶,FF
为什么IE10要去掉标签(我真的很惊讶,FF和Chrome没有把它去掉 URL散列(不是“散列标签”)纯粹是客户端功能,通常根本不会发送到服务器 浏览器使用URL(不带哈希)从服务器请求文档,然后查找ID与哈希匹配的元素并滚动到该元素
参见例如和类似问题。解决方案是在表单中插入一个名为“action”的隐藏字段 我还包含了一段jQuery代码,用于从URL获取所需的值
// Find out what needs to be done
var action = window.location.hash.substring(1);
// IE specific code: pick up the GET data
if (action == '') {
$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null){
return null;
}
else {
return results[1] || 0;
}
}
action = $.urlParam('action');
}
你们似乎不明白我们实际上是如何处理这些散列的。我完全知道散列只是一个客户端功能。我已经添加了一些代码…请看一下。。。
<a href="http://www.example.com/package-standard-print/#skipnamecheck">Choose</a>
http://www.example.com/name-check/?gle=namecheck&name=REGERGERGERGERGER#packthree
http://www.example.com/name-check/?gle=namecheck&name=GR4EGWERGWERGEHGUKYKUWEGWERGEGERGEGRRG
// Find out which package we are dealing with
var action = window.location.hash.substring(1);
switch(action) {
case 'namecheckpath':
// Page of interest: /name-check/
// Path: Home -> Name Search -> Confirm Name -> Grid -> Package page -> Extras -> Checkout
// What needs to be done:
// 1. Next page has to be grid
$(".stepactive2").removeClass('stepactive2').addClass('stepinactive2');
$('a[href^="/buy/"]').attr('href', '/package-comparison/#gridskipnamecheck');
$('form[action^="/name-check/"]').attr('action', '/name-check/#namecheckpath');
// 2. Steps - remove class from second step (Package) so that the highlighting works well
break;
case 'packone':
// Page of interest: /name-check/
// Path: Home -> Choose package (2-5) -> Name Search -> Confirm Name -> Extras -> Checkout
// What needs to be done:
// 1. Next page is the extras page for a chosen package
$('.stepactive2').text("Choose package");
$('.stepinactive3').text("Build package");
$('a[href^="/buy/"]').attr('href', '/buy/self-build-flatpack/#selfbuild');
$('form[action^="/name-check/"]').attr('action', '/name-check/#packone');
break;
case 'packtwo':
// Page of interest: /name-check/
// Path: Home -> Choose package (2-5) -> Name Search -> Confirm Name -> Extras -> Checkout
// What needs to be done:
// 1. Next page is the extras page for a chosen package
$('a[href^="/buy/"]').attr('href', '/buy/basic-digital/');
$('form[action^="/name-check/"]').attr('action', '/name-check/#packtwo');
break;
case 'packthree':
// Page of interest: /name-check/
// Path: Home -> Choose package (2-5) -> Name Search -> Confirm Name -> Extras -> Checkout
// What needs to be done:
// 1. Next page is the extras page for a chosen package
$('a[href^="/buy/"]').attr('href', '/buy/standard-print/');
$('form[action^="/name-check/"]').attr('action', '/name-check/#packthree');
break;
case 'packfour':
// Page of interest: /name-check/
// Path: Home -> Choose package (2-5) -> Name Search -> Confirm Name -> Extras -> Checkout
// What needs to be done:
// 1. Next page is the extras page for a chosen package
$('a[href^="/buy/"]').attr('href', '/buy/premium-print/');
$('form[action^="/name-check/"]').attr('action', '/name-check/#packfour');
break;
case 'packfive':
// Page of interest: /name-check/
// Path: Home -> Choose package (2-5) -> Name Search -> Confirm Name -> Extras -> Checkout
// What needs to be done:
// 1. Next page is the extras page for a chosen package
$('a[href^="/buy/"]').attr('href', '/buy/all-inclusive/');
$('form[action^="/name-check/"]').attr('action', '/name-check/#packfive');
break;
case 'gridskipnamecheck':
// Page of interest: /package-comparison/
// Path: Home -> Name Search -> Confirm Name -> Grid -> Package page -> Extras -> Checkout
$('a[href^="/package-"]').each(function() {
this.href += '#skipnamecheck';
});
break;
case 'skipnamecheck':
// Page of interest: /package-xxx/
// Path: Home -> Name Search -> Confirm Name -> Grid -> Package page -> Extras -> Checkout
if(window.location.href.indexOf("package-self-build") > -1) {
$('a[href^="/name-check-"]').attr('href', '/buy/self-build-flatpack/#selfbuild');
} else if(window.location.href.indexOf("package-basic-digital") > -1) {
$('a[href^="/name-check-"]').attr('href', '/buy/basic-digital/');
} else if(window.location.href.indexOf("package-standard-print") > -1) {
$('a[href^="/name-check-"]').attr('href', '/buy/standard-print/');
} else if(window.location.href.indexOf("package-premium-print") > -1) {
$('a[href^="/name-check-"]').attr('href', '/buy/premium-print/');
} else if(window.location.href.indexOf("package-all-inclusive") > -1) {
$('a[href^="/name-check-"]').attr('href', '/buy/all-inclusive/');
}
break;
default:
//console.log('default');
}
// Find out what needs to be done
var action = window.location.hash.substring(1);
// IE specific code: pick up the GET data
if (action == '') {
$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null){
return null;
}
else {
return results[1] || 0;
}
}
action = $.urlParam('action');
}