如跨域在Chrome正常,火狐浏览器提示 firefox with reason: CORS header ‘Access-Control-Allow-Origin’ does not match ‘http://localhost:4200, *’). 则应检查 火狐浏览器是否有安装 cors 相关插件 参考链接:firefox with reason: CORS header ‘Access-Control-Allow-Origin’ does not match ‘http://localhost:4200, *’).
// Chrome allows you to simply tweak the HREF of the LINK tag. // Firefox appears to require that you remove it and readd it. functionsetFavicon(url) { removeFavicon(); var link=document.createElement('link'); link.type='image/x-icon'; link.rel='icon'; link.href=url; document.getElementsByTagName('head')[0].appendChild(link); if (window.console) console.log("Set FavIcon URL to " + getFavicon().href); }
functionremoveFavicon() { var links=document.getElementsByTagName('link'); var head=document.getElementsByTagName('head')[0]; for(var i=0; i<links.length; i++) { if(links[i].getAttribute('rel')==='icon'){ head.removeChild(links[i]) } } }
let RESERVED_CHAR_SET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.~_'
functionget_normalized_char(b) { let result = newMap() for (let i = 0; i < 256; i++) { // 转ASCII码,跟java, Char temp = (char)i ; 一样 let c = String.fromCharCode(i) if (!b && c === '/') { continue } if (RESERVED_CHAR_SET.indexOf(c) !== -1) { result.set(c, c) } else { // 转16进制 let temp = i.toString(16).toUpperCase() // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart result.set(c, '%' + temp.padStart(2, '0')) } } return result }
window.encodString = function(path, b) { let length = path.length let result = '' let encode_f = get_normalized_char(b)
for (let i = 0; i < length; i++) { if (path.charAt(i) === '/' && !b) { result += '/' } let c = encode_f.get(path.charAt(i)) if (!c) { continue } result += c } return result }
获取指定时区时间(中国)
方案1,兼容IE,chrome
1 2 3 4 5
var timezone = 8; //目标时区时间,东八区 var offset_GMT = new Date().getTimezoneOffset(); // 本地时间和格林威治的时间差,单位为分钟 var nowDate = new Date().getTime(); // 本地时间距 1970 年 1 月 1 日午夜(GMT 时间)之间的毫秒数 var targetDate = new Date(nowDate + offset_GMT * 60 * 1000 + timezone * 60 * 60 * 1000); console.log("东8区现在是:" + targetDate);