Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.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 在站点上使用target\u blank会强制移动重定向,即使在桌面上也是如此_Javascript_Django_Angularjs_Redirect_Mobile - Fatal编程技术网

Javascript 在站点上使用target\u blank会强制移动重定向,即使在桌面上也是如此

Javascript 在站点上使用target\u blank会强制移动重定向,即使在桌面上也是如此,javascript,django,angularjs,redirect,mobile,Javascript,Django,Angularjs,Redirect,Mobile,我有两个网站,一个是手机网站,一个是桌面网站。这两个网站都是使用angular构建的django应用程序。桌面站点似乎有一个bug,其中生成的任何链接都应该传递移动重定向并继续发送到桌面,但是,它们没有传递此错误,只有在链接上使用target=\u blank时才会重定向 在controllers.js中,我有以下内容: $(document).ready(function(){ //showA(); mobileRedirect(); if($route.current.param

我有两个网站,一个是手机网站,一个是桌面网站。这两个网站都是使用angular构建的django应用程序。桌面站点似乎有一个bug,其中生成的任何链接都应该传递移动重定向并继续发送到桌面,但是,它们没有传递此错误,只有在链接上使用target=\u blank时才会重定向

在controllers.js中,我有以下内容:

$(document).ready(function(){
  //showA();
  mobileRedirect();
  if($route.current.params.aId){
    a.set($route.current.params.aId,$route.current.params.bId);
  };
  tryCookieLogin();
});
现在,移动重定向基于:

function mobileRedirect() {
    var viewport = getWindowSize();
     console.log('viewport: '+viewport.width)
    if (viewport.width<650){
      //console.log('switch to mobile')
      if(isA()){
        var urlA = 'http://example.com/mobile/#/a/'+$route.current.params.aId+'/b/'+$route.current.params.bId;
      }else{
        var urlA = 'http://example.com/mobile/';
      }
      window.location.href = urlA;
    }
}

那么,为什么如果我使用target=_空白链接,不管屏幕大小如何,它都会重定向到mobile?而不使用目标的链接工作正常?

GetWindowsSize函数返回窗口的宽度和高度,而不是设备屏幕的宽度


因此,如果在桌面上使用target=_blank创建一个新窗口,并且该窗口的宽度小于650px,那么它将受到移动重定向的影响。

Hi@redband。你的问题从未得到回复。如果我的答案有帮助,请投票并奖励答案。谢谢!
function getWindowSize() {
    var w = window,
        d = document,
        e = d.documentElement,
        g = d.getElementsByTagName('body')[0],
        x = w.innerWidth || e.clientWidth || g.clientWidth,
        y = w.innerHeight || e.clientHeight || g.clientHeight;

        $scope.windowWidth

    return { width: x, height: y };
}