Utilizing the target="_blank" attribute on a website is causing an automatic redirection to the mobile version

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?

Answer №1

When utilizing the getWindowSize() method, it provides the dimensions of the browser window rather than the device screen width.

Therefore, should a new window be opened with target="_blank" on a desktop that is narrower than 650px, it may trigger the mobile redirect).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transferring Information from Controller to HTML Template

I have been working on passing data from a controller to an HTML template. I can see the data in the console.log, but for some reason, it's not displaying in the DOM. Here is my COMPONENT: import ItemService from '../../services/test.service.js ...

Unable to display label in form for Angular 2/4 FormControl within a FormGroup

I'm having trouble understanding how to: Use console.log to display a specific value Show a value in a label on an HTML page Display a value in an input text field Below is my TypeScript component with a new FormGroup and FormControls. this.tracke ...

Unable to locate the index.js entry file in React Native

I have a simple React Native application. I am attempting to test it on a virtual Android device by navigating to the project and running npm start -- --reset-cache. After terminating the process, I enter the command react-native run-android. Despite havin ...

Exploring the use of custom properties within the multiCapabilities configuration object

Within my multiCapabilities config property, I've defined a custom property called screenSize, like this: multiCapabilities: [{ browserName: 'chrome', screenSize: 'large', chromeOptions : { args: [ ' ...

Utilize Javascript to compare nested objects and store the differences in a separate object

I have a dilemma involving two JavaScript objects var order1 = { sandwich: 'tuna', chips: true, drink: 'soda', order: 1, toppings: [{VendorNumber: 18, PreferredFlag: false, SupportedFlag: true}, {VendorNumber: 19, ...

Issues with AngularJS checkbox filters functionality not performing as expected

I am tasked with implementing a filter feature using checkboxes for certain properties. Here is the code I have written: JavaScript code: app.controller("filterCtrl", function ($scope, $http) { $http({ method: 'GET', url: contextPath + ...

Guide on altering the background color of a table row depending on the data in its cells with the help of AngularJS

I am looking to dynamically change the background color of a row based on specific cell data. If the first four characters in a table cell match a certain value, I want the entire row to change its color to red. Currently, my code changes the row color ba ...

Input specific ng-if conditions

I'm a bit confused about the conditions for my ng-if and could use some assistance. I have a form on my page that is rendered using ng-repeat and a couple of custom filters. You can check out this plunker. The issue I'm facing is that I need to p ...

ES7 Map JSON introduces a new feature by using square brackets

Currently, I am utilizing core-js for the Map collection because it appears that ES7 Map includes a Map to JSON feature that is absent in ES6 Map. (ES6): JSON.stringify(new Map().set('myKey1', 'val123').set('myKey2', 'va ...

Despite creating precise tests for the URLs in Django, the code coverage still does not include them

In my backoffice_engine app, the urls.py file appears as shown below: from django.urls import path, include from . import views urlpatterns = [ path('test/', views.test, name='test'), path('', views.dashboard, name=&a ...

Incorporate a section of HTML code into the 'templateUrl' of

Is it possible to specify only a portion of a file as the templateUrl for your Angular directive? For instance, if I have a file containing: <input type="text" data-name="first-name" /> <input type="text" data-name="last-name" /> <input t ...

Django: Calculating the Total Sum of Values Linked by Foreign Keys

I am currently utilizing Django version 1.11 along with Python3.5 I have established a table. Here is a snapshot. https://i.sstatic.net/E0bX8.png Whenever I retrieve a table from my database query, it displays numbers like 10+2+3... instead of providing t ...

JavaScript Geocoding does not initiate the search process

Currently in the process of moving some Google Maps functions to a separate file. In my main file, I have a function search() that sets up a workflow with the other file included. The issue I'm facing is with the geocoder.geocode() function, which was ...

Common issues encountered when using the app.get() function in Node.js

I've been attempting to develop a website that utilizes mongojs. I've implemented the code snippet below, but when I launch the site, it never reaches the app.get() section, resulting in a 500 error on the site. How can I ensure it responds to th ...

Using a jquery function within a Laravel view

I am trying to retrieve a selected item from a dropdown menu using jQuery and then redirect it to a controller function. This function will return some data to be displayed based on the selected item. I could really use some assistance with this. Here is m ...

The scrolling behavior varies in Firefox when using the mouse wheel

Currently, I am working on a website where I want to display large text on the screen and have the ability to scroll two divs simultaneously. This functionality is already in place. I can scroll the divs, but I'm facing an issue with the jumps being t ...

The Intellisense feature does not function properly when attempting to import the module from a Content Delivery Network in Visual Studio Code

My process of importing three.js looked like this: import { WebGLRenderer } from 'three'; Initially, the autocomplete feature was working perfectly fine (displayed in image 1). However, when I tried to import from a CDN using the following synt ...

Unspecified error encountered in the VUE selection view

I am facing an issue with the undefined value in the select view while attempting to add a new project. Could you suggest a solution? I tried using v-if but it didn't work for me. This is how my code looks: <v-select v-model="pro ...

Securely transmit data using a JQuery modal dialog form with HTTPS encryption

I currently have a functional modal login dialog. The only issue I'm facing is that when the original page is loaded through http, I still need to securely pass credentials to the server via https. Ideally, I would like to achieve this with minimal mo ...

Executing API calls directly within the `useEffect()` function

I am inquiring about the functionality of useEffect() in a function component. This script fetches data from a server and displays it. const NameList = (props) => { const [result, setResult] = useState([]); useEffect(() => { var url = `http ...