Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening new tabs via Phaser logic will cause those tabs to be blocked by Chrome's popup blocker #4106

Closed
maximtsai opened this issue Oct 10, 2018 · 1 comment

Comments

@maximtsai
Copy link

maximtsai commented Oct 10, 2018

  • Phaser Version: Version 3.14
  • Operating system: Windows 10
  • Browser: Chrome

Description

Trying to open a new tab via a 'pointerup' event (or any pointer event) in Phaser will result in Chrome's popup blocker being triggered. The same action done via a document.addEventListener('mouseup', myFunction) event won't trigger Chrome's popup blocker. This means I can't add in-game buttons that do things such as redirect a user to my website unless they explicitly allow popups.

Example Test Code

var config = {
    type: Phaser.AUTO,
    width: 400,
    height: 300,
    backgroundColor: '#111111',
    parent: 'phaser-example',
    scene: {
        preload: preload,
        create: create
    }
};
var game = new Phaser.Game(config);

function preload ()
{
    this.load.image('button', 'button.png');
}

function create ()
{
    var myButton = this.add.image(200, 150, 'button');
    myButton.setInteractive();
    // clicking on the button will trigger Chrome's popup blocker instead of going to google.com
    myButton.on('pointerup', () => {window.open('https://www.google.com')}, this);
}

Using document.addEventListener to trigger window.open() will open the new tab at Google without fuss, but of course this means clicking anywhere in the game will cause the new tab to open.

function create ()
{
    var newImage = this.add.image(200, 150, 'box');
    newImage.setInteractive();
    //newImage.on('pointerup', () => {window.open('https://www.google.com')}, this);
    document.addEventListener('mouseup', () => {window.open('https://www.google.com')});
}

Additional Information

image

@photonstorm
Copy link
Collaborator

https://photonstorm.github.io/phaser3-docs/Phaser.Input.InputPlugin.html#addUpCallback__anchor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants