Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript js ecwid url重定向_Javascript_Ajax_Redirect - Fatal编程技术网

Javascript js ecwid url重定向

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#!/

我一直在尝试为一系列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 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