Tips for keeping the current tab active when a link opens a new tab using Javascript

There are many posts on this, but none seem to have a solution.I think it can be done.

If you have a link with target='_blank', the page will open in a new tab, and it will be in focus.

However, if you press the CTRL key when you click that link, the new tab will be in the background. Therefore, if you can use JavaScript to simulate a CTRL press, it should work.

I saw someone post a code trying this, but it was old and used initMouseEvent which is depreciated. I think that's why it didn't work. Could there be a simple way to do this, something like...

<a href='https://example.com' onclick='...code to simulate CTRL key here...'>CLICK ME</a>

Answer №1

It is impossible to achieve compatibility with current browsers using the deprecated methods that were once available.

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

How to extract dynamic content efficiently by combining Selenium and Scrapy for multiple initial URLs

I have been assigned the task of developing a web scraper for a property website where the data will be collected and stored for future analysis. The website is a national platform that requires users to select a region before displaying any results. In ...

Guide to accessing HTML elements and saving them in a JSON formatted text using JavaScript

If you have an html form with labels, select boxes, and radio buttons, you can use javascript to store the child elements of that form in a json string format. Here is an example: { "label": { "content": "This is a label" }, "textbox" ...

Error occurred due to an invalid element type with the imported React component

Using a component imported from an npm package in two different apps has resulted in unexpected behavior. In one app, the component functions perfectly as expected. However, in the other app, an error is raised: Element type is invalid: expected a string ...

Tips for including a decimal point in an angular reactive form control when the initial value is 1 or higher

I am trying to input a decimal number with 1 and one zero like 1.0 <input type="number" formControlName="global_velocity_weight" /> this.form = this.fb.group({ global_velocity_weight: new FormControl(1.0, { validators: [Valida ...

Implementing CSS styles on selected elements using jQuery

My current HTML layout looks like this.. <div class="container> <div class="panel"> <div> <div> <div> <img class="match" src="myimage.jpg"> &l ...

I am in the process of creating several checkboxes and am looking to incorporate some added functionality

Currently, I am working on a project that involves creating multiple checkboxes. My goal is to implement a specific functionality where only one checkbox can be checked in each group with the correct or incorrect value. Once all groups have been selected, ...

Trigger event listener of AngularJS directive on click and send information to it

During my exploration of AngularJS directives, I encountered a task that required me to activate the directive's listener upon clicking a button and passing data from the controller to it. Sample Directive app.directive('graphVisualization&apos ...

Is it possible to utilize a pre-existing JS "package" with Node.JS?

Recently, I decided to convert my existing JS code into an NPM package for easier distribution. The package is called "my-pkg" and includes the following files: my-pkg.js package.json my-pkg.js function ping() { console.log("Hi!"); } package.json ...

Unable to access a specific URL for the chosen items

I am looking to navigate to specific links when clicking on particular planets using raycaster. However, the current issue is that I get redirected to the URL of the last planet (referred to as category) whenever I click anywhere on the canvas. I have sepa ...

Dynamic updates using Ajax after a change in the trigger

In my current project, I am in the process of developing a textarea that will trigger an ajax request whenever it is changed. However, I am concerned about overloading the server with too many requests since the purpose of this request is to save the con ...

Lunar - incorporate route parameter into DOM query_operation

Is there a way to take a route parameter and use it to trigger a click event on a DOM element? The issue is that onBeforeAction is called before the DOM is fully loaded. Any suggestions on how to solve this problem? JS onBeforeAction: function(){ var ...

Is there a specific advantage to iterating through arrays backwards in JavaScript?

Is it common practice in Javascript to use the following loop: for (var i = array.Length - 1; i >= 0; i--) { /* do something here */ }; I haven't seen this in other languages. Are there any advantages to this compared to: for (var i = 0; i < ...

What is the method for initiating an event from iframe content to an external website?

Currently, I am developing a chat-bot that is designed to function across all domains. For example, let's say my chat-bot is hosted on 'chat.mybot.com' as an iframe using Angular, and my website is 'example.com'. Due to the differe ...

Check out the source code of the file causing the redirection

Whenever I click on a URL, it triggers a redirect using the window.location function. I am curious to examine the code within this HTML file. Unfortunately, as it is constantly redirecting, I am finding it difficult to access the source code. Is there a w ...

Is the original object cloned or passed by reference when passing it to a child React component through props?

When passing an object to a child component through the components props in React, does the object get cloned or does it simply pass a reference to the original object? For instance, in my App.js, I am importing a JSON object called ENTRY_DATA. Then, I pa ...

Displaying PDF files on the internet without allowing them to be downloaded

How can I display PDF files on my website without allowing them to be saved or downloaded? Is there a way to prevent browsers from saving or downloading the PDF files? ...

There seems to be an issue with JSX rendering correctly in the code

My JSX code is not rendering properly on my React webpage, and instead of the expected output, I am seeing: <div class='card'>NaNSasha<img src= NaN />Boddy Cane</div>. Here is the component's code: import React, { Componen ...

Prioritize returning AJAX data over iterating through the parent loop

Hey everyone, I'm having trouble wrapping my head around this issue even after researching various scenarios online. Here's what's going on: I have an array of strings named recipientsList. What I want to do is make an AJAX call for each s ...

Transfer external variables into the image's onload function

I am trying to retrieve image dimensions and then execute additional actions. Since the image onload function is asynchronous, I have decided to handle everything within the onload call. This is my current approach: function getMeta(url, callback) { v ...

Creating a custom Angular filter to group every 3 items within an iteration into a new div container

When attempting to organize three instances of app-story-preview within a wrapper div using a ngFor loop, I encountered the following code: <ng-template [ngIf]="stories.length > 0" [ngIfElse]="empty"> <cdk-virtual-scroll-viewport [itemSize ...