How to activate a window that's been minimized in Chrome

I am experiencing an issue with a button that is supposed to open a new window as a popup below the parent page. It works correctly in IE and Firefox, but in Chrome, the popup appears on top of the parent window.

Can someone please provide a solution?

For example, when visiting kayak.com or another travel website, you have the option to search on other websites. I want to implement something similar and require the pop-under functionality.

The code I am currently using is window.open(.......).blur(), but it doesn't seem to work in Chrome for some reason.

Answer №1

After reconsidering, I have come to the conclusion that it is indeed possible.

The solution below is what worked for me personally (tested on the latest production version of Chrome).

const url = "yourURL.html";
window.open(url, "s", "width= 640, height= 480, left=0, top=0, resizable=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no").blur();
window.focus();

Remember, it's important not to annoy your website visitors as it may result in a decrease in traffic.

Answer №2

function createPopunder(pUrl) {
    var _parent = (top != self && typeof (top["document"]["location"].toString()) === "string") ? top : self;
    var mypopunder = null;
    var pName = (Math["floor"]((Math["random"]() * 1000) + 1));
    var pWidth = window["innerWidth"];
    var pHeight = window["innerHeight"];
    var pPosX = window["screenX"];
    var pPosY = window["screenY"];
    var pWait = 3600;
    pWait = (pWait * 1000);
    var pCap = 50000;
    var todayPops = 0;
    var cookie = "_.mypopunder";
    var browser = function () {
        var n = navigator["userAgent"]["toLowerCase"]();
        var b = {
            webkit: /webkit/ ["test"](n),
            mozilla: (/mozilla/ ["test"](n)) && (!/(compatible|webkit)/ ["test"](n)),
            chrome: /chrome/ ["test"](n),
            msie: (/msie/ ["test"](n)) && (!/opera/ ["test"](n)),
            firefox: /firefox/ ["test"](n),
            safari: (/safari/ ["test"](n) && !(/chrome/ ["test"](n))),
            opera: /opera/ ["test"](n)
        };
        b["version"] = (b["safari"]) ? (n["match"](/.+(?:ri)[\/: ]([\d.]+)/) || [])[1] : (n["match"](/.+(?:ox|me|ra|ie)[\/: ]([\d.]+)/) || [])[1];
        return b;
    }();

    function checkIfCapped() {
        try {
            todayPops = Math["floor"](document["cookie"]["split"](cookie + "Cap=")[1]["split"](";")[0]);
        } catch (err) {};
        return (pCap <= todayPops || document["cookie"]["indexOf"](cookie + "=") !== -1);
    };

    function executePopunder(pUrl, pName, pWidth, pHeight, pPosX, pPosY) {
        if (checkIfCapped()) {
            return;
        };
        var sOptions = "toolbar=no,scrollbars=yes,location=yes,statusbar=yes,menubar=no,resizable=1,width=" + pWidth.toString() + ",height=" + pHeight.toString() + ",screenX=" + pPosX + ",screenY=" + pPosY;
        document["onclick"] = function (e) {
            if (checkIfCapped() || window["pop_clicked"] == 1 || pop_isRightButtonClicked(e)) {
                //return;
            };
            window["pop_clicked"] = 1;
            mypopunder = _parent["window"]["open"](pUrl, pName, sOptions);
            if (mypopunder) {
                var now = new Date();
                document["cookie"] = cookie + "=1;expires=" + new Date(now["setTime"](now["getTime"]() + pWait))["toGMTString"]() + ";path=/";
                now = new Date();
                document["cookie"] = cookie + "Cap=" + (todayPops + 1) + ";expires=" + new Date(now["setTime"](now["getTime"]() + (84600 * 1000)))["toGMTString"]() + ";path=/";
                executeUnderPopup();
            };
        };
    };

    function executeUnderPopup() {
        try {
            mypopunder["blur"]();
            mypopunder["opener"]["window"]["focus"]();
            window["self"]["window"]["blur"]();
            window["focus"]();
            if (browser["firefox"]) {
                launchAndCloseWindow();
            };
            if (browser["webkit"]) {
                launchAndCloseTab();
            };
        } catch (e) {};
    };

    function launchAndCloseWindow() {
        var ghost = window["open"]("about:blank");
        ghost["focus"]();
        ghost["close"]();
    };

    function launchAndCloseTab() {
        var ghost = document["createElement"]("a");
        ghost["href"] = "about:blank";
        ghost["target"] = "PopHelper";
        document["getElementsByTagName"]("body")[0]["appendChild"](ghost);
        ghost["parentNode"]["removeChild"](ghost);
        var clk = document["createEvent"]("MouseEvents");
        clk["initMouseEvent"]("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
        ghost["dispatchEvent"](clk);
        window["open"]("about:blank", "PopHelper")["close"]();
    };

    function pop_isRightButtonClicked(e) {
        var rightclick = false;
        e = e || window["event"];
        if (e["which"]) {
            rightclick = (e["which"] == 3);
        } else {
            if (e["button"]) {
                rightclick = (e["button"] == 2);
            };
        };
        return rightclick;
    };
    if (checkIfCapped()) {
        return;
    } else {
        executePopunder(pUrl, pName, pWidth, pHeight, pPosX, pPosY);
    };
}

createPopunder("http://www.yourdomain.com/");

Answer №3

The era of popunders has come to a close. Google Chrome shut it down just yesterday.

Answer №4

Here is a solution for Chrome (tested on version 40 as of 29/01/2015). Instead of opening a popup window, this method opens a new tab and does not maintain focus on the main tab anymore (focus behavior changes in Chrome version 43>).

To bypass popup blockers, user interaction is necessary. Specifically, you should use the mousedown or mouseup event as using click will trigger a popup blocker warning.

document.addEventListener("mousedown", tabUnder);

function tabUnder() {
    var a = document.createElement("a"),
        e = document.createEvent("MouseEvents");
    a.href = "http://testit.com"; //the URL of the 'popup' tab
    e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
    a.dispatchEvent(e);
    document.removeEventListener("mousedown", tabUnder);
}

-View jsFiddle Example-

Answer №5

Here is an alternative method to handle popups:

var MINUTE_MILLISECONDS = 60000;
var now = new Date().getTime();

if (!localStorage.t || now > parseInt(localStorage.t) + MINUTE_MILLISECONDS) {
    var date = new Date();
    localStorage.t = now;
    window.location.href = "http://dgsprb.blogspot.com/";
    window.open(window.document.URL, "_blank");
}

This approach ensures that the new content remains on the current tab while opening a new tab with the original window content. It functions similarly to a pop under, allowing for the reloading of the current window as needed. Additionally, it prevents the popup from appearing more than once per minute.

Answer №6

The enigmatic script by @dixie functions smoothly for me on Firefox, Internet Explorer, and nearly on Chrome (although it does not focus on the main window but rather on the pop-up).

To ensure flawless operation on Google Chrome, I found that adding the following lines helped regain focus:

path = window.document.URL;
window.open(path,"_self");

Answer №7

This particular snippet has been tested to function properly on Chrome browsers up until version 65:

function launchWindow() {
    postMessage([...arguments]);
}
window.onmessage = function({data}){
    return open(...data);
}
function newLaunch() {
    launchWindow([...arguments]);
    window.open().close();
}

The key difference with newLaunch compared to open() is:

  • No value returned
  • Incompatible with Chrome versions 65 and above, as documented here

Answer №8

Important Update: Unfortunately, this method is no longer effective.


Here is the solution from before:

window.open('http://google.com','','height=500,width=500');
window.open().close();

Remember to always use popunders ethically and responsibly.

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

I am having trouble getting Vue.js to function properly within HTML when using Django. Can someone please lend me a

The code run Here is the HTML document: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Register</title> <!--javascript extensions--> <script src=' ...

Merging arrays with the power of ES6 spread operator in Typescript

My goal is to merge two arrays into one using the spread object method as shown in the code snippet below: const queryVariable = { ...this.state, filters: [...Object.keys(extraFilters || {}), ...this.state.filters], } The this.state.filte ...

Convert Python strings into HTML JavaScript blocks using Jinja2

Having trouble passing a string to an HTML page in the "<script>" block. I am currently using Python, Flask, and Jinja2. Python code: def foo(): return myString #"[{title: 'Treino 7-Corrida',start: '2015-12-08',color: '#d ...

Adding an external script to a Vue.js template

Delving into the world of Vue.js and web-pack, I opted to utilize the vue-cli (webpack) for scaffolding an initial application. A challenge arose when attempting to incorporate an external script (e.g <script src="...") in a template that isn't req ...

Warning from Google Chrome: Ensure password forms include optional hidden username fields for improved accessibility

Upon visiting the "reset password" route of my single-page application and checking the Chrome browser console, I am presented with a warning message: [DOM] Password forms should contain (optionally hidden) username fields for accessibility: (More info: g ...

I encountered an issue while attempting to manipulate/retrieve the JSON value using REGEX, resulting in an undefined return

I am attempting to retrieve the currency value from a JSON file and if it is USD, then I want to change it to AUD. When trying to find the currency attribute in the JSON file, it returned 'undefined' as shown below: Code: var datastring = JSON. ...

unable to send array in cookie through express isn't functioning

Currently, I am in the midst of a project that requires me to provide the user with an array. To achieve this, I have been attempting to utilize the res.cookie() function. However, each time I try to pass an array as cookie data, the browser interprets it ...

Endless AngularJS loop using ng-view

I recently started experimenting with AngularJS for a new project I am working on, but I have encountered a problem when dealing with routes and views. For the sake of simplicity, I have minimized this example to its basic form, yet the issue persists. Th ...

Inhibit the ASP:dropdownlist when the value of another ASP:Dropdownlist is selected

Trying to modify two asp.net dropdownlists using client-side JavaScript is my current challenge. Specifically, these dropdowns are located within a modal that opens with a function. The objective is to disable the second dropdown (dropdown2) whenever the ...

The occurrence of the "contextmenu" event can cause disruption to the execution of a function triggered by the "onmousemove" event

Currently in the process of developing a Vue application utilizing a Pinia store system. Within my BoxView.vue component, I have created a grid layout with draggable elements that have flip functionality implemented within the BoxItem.vue component. Spec ...

What is the best method for transforming a nested object into an array of objects?

This object contains nested data var arr = [{ "children": [{ "children": [{ "children": [], "Id": 1, "Name": "A", "Image": "http://imgUrl" }], "Id": 2 "Name": "B", ...

Identify the failing test cases externally using JavaScript

I am currently tackling an issue where I am seeking to identify the specific test cases that fail when running a test suite for any javascript/node.js application. Finding a programmatic solution is crucial for this task. Mocha testsuite output result Fo ...

Tips for swapping hosts in Postman and JavaScript

Is there a simple way to allow the front-end and testing teams to easily override the host header to match {tenant}.mydomain.com while working locally? I'm looking for a solution that doesn't involve constant changes. Any ideas on how I can achie ...

What are the best ways to keep a django page up to date without the need for manual

Currently, I am in the process of developing a Django website focused on the stock market. Utilizing an API, I am pulling real-time data from the stock market and aiming to update the live price of a stock every 5 seconds according to the information pro ...

Is it possible to pass the image source to a Vue.js component through a

I am encountering an issue while trying to display an image in the designated location within display.vue. Even though {{ someText }} returns the correct file path (../assets/city.png), the image is not being output correctly. Here is how my code looks: ...

Design a dynamic table using JavaScript

After spending hours working on my first JavaScript code, following the instructions in my textbook, I still can't get the table to display on my webpage. The id="eventList" is already included in my HTML and I've shortened the arrays. Here' ...

filtering elements with selectable functionality in jQuery UI

I'm trying to exclude the <div> children from being selected within this list item and only select the entire <li>. The structure of the HTML is as follows: <ul id="selectable"> <li> <div id="1"></div> ...

Setting up an i18n project in AngularJS

I just embarked on my angularjs journey yesterday with little to no prior knowledge about it. My initial goal is to centralize all the labels for my UI in a file (to facilitate swapping them out for i18n). As far as I know, this can be achieved by importi ...

Tips on preventing the opening of a new browser tab by using Ctrl + click

Hey there, I've got a list of products that can be selected using the Ctrl key. $(parentSelector).on("click", function (evnt) { evnt.stopImmediatePropagation(); var item = $(evnt.delegateTarget) ...

The error message "SharedArrayBuffer is not defined" occurred when attempting to utilize ffmpeg.wasm

<!DOCTYPE html> <html> <head> <title>TikTok Live Downloader</title> </head> <body> <h1>TikTok Live Downloader</h1> <label for="username">Username:</label> ...