I am encountering an issue on my two websites - one for mobile and another for desktop. Both sites are built with django apps using angular. The problem lies in the desktop site, where the links generated are supposed to pass through the mobile redirect before taking users to the desktop version. However, this redirection is not happening as expected. Strangely, only when I use target="_blank"
attribute on a link does it redirect properly.
Within controllers.js
, the following code snippet can be found:
$(document).ready(function(){
//showA();
mobileRedirect();
if($route.current.params.aId){
a.set($route.current.params.aId,$route.current.params.bId);
};
tryCookieLogin();
});
The function for mobile redirect looks like this:
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;
}
}
Additionally, there is a method called getWindowSize which determines the size of the window:
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 };
}
The puzzling part is why links with target="_blank"
always redirect to the mobile site, regardless of screen size, while links without the target attribute work fine on the desktop version. What could be causing this unexpected behavior?