Javascript js ecwid url重定向
我一直在尝试为一系列ecwid URL设置重定向,这些URL从/shop到/shop#!/~/通往/购物#/~/推车 我想出了以下代码:Javascript js ecwid url重定向,javascript,ajax,redirect,Javascript,Ajax,Redirect,我一直在尝试为一系列ecwid URL设置重定向,这些URL从/shop到/shop#!/~/通往/购物#/~/推车 我想出了以下代码: var错误\u url=['http://example.com/shop','http://example.com/shop#','http://example.com/shop#!','http://example.com/shop#!/','http://example.com/shop#!/~','http://example.com/shop#!/
var错误\u url=['http://example.com/shop','http://example.com/shop#','http://example.com/shop#!','http://example.com/shop#!/','http://example.com/shop#!/~','http://example.com/shop#!/~/'];
var current_url=document.url;
对于(i=0;iVitaly,此处为Ecwid
当前版本的脚本中存在的问题是,它没有检测到对URL的更改,如您所述
因此,您需要为此类情况分别创建一个处理程序。例如,您可以这样做:
<script>
var wrong_url = ['http://example.com/shop','http://example.com/shop#','http://example.com/shop#!','http://example.com/shop#!/','http://example.com/shop#!/~','http://example.com/shop#!/~/'];
var current_url = document.URL;
// function to check current URL and make a redirect
function checkUrl(){
for (i=0;i<wrong_url.length;i++) {
if (current_url==wrong_url[i]) {
document.location.replace('http://example.com/shop#!/~/cart');
break;
}
}
}
// Execute checkUrl() function each time URL is changed
$(window).bind('hashchange', function() {
checkUrl();
});
// Execute checkUrl() function on initial page load
checkUrl();
</script>
var错误\u url=['http://example.com/shop','http://example.com/shop#','http://example.com/shop#!','http://example.com/shop#!/','http://example.com/shop#!/~','http://example.com/shop#!/~/'];
var current_url=document.url;
//函数检查当前URL并进行重定向
函数checkUrl(){
对于(i=0;i