[SOLVED] Window.open() doesn't work in Safari in iPhone

window.open() doesn’t work in safari in iPhone.
“Doesn’t work” means it does not open a window when it is called. Nothing happens.

It works in Safari in iPad.
It works in Safari in desktop.
It works in chrome in anywhere.

Has anybody addressed this problem yet?

Hi @lenvanthis,

Yes, that’s an issue with Safari on iPhone, not related with PlayCanvas.

I’m not sure if there is anything you can do with JavaScript to address that. The only way is to show some HTML elements that include a clickable a href link for the user to click.

Thank you for the response. By any chance, do you know any example of clickable html element with a href link? All so too new to me. Thanks a lot.

1 Like

So, go to this example and fork it:


And from there update the html asset with the following HTML:

<div class='button'>BUTTON</div>
<div class='counterBox'>
    times clicked <span class='counter'>0</span>
<div class='text'>
    Hit the button to <a href="https://playcanvas.com" target="_blank">increment</a> the counter<br />

That will make the increment word become a link that opens the playcanvas.com page on a new tab.


Are you trying to do this on a PlayCanvas UI button? If so, you may want to do something similar to Capturing a screenshot | Learn PlayCanvas where we use a HTML element and call click on it.



That is a freaking helpful info. Amazing. Looking forward to testing out what I learned from your code.

Thanks, again.

Thank you for the info again, Leonidas.

OMG… Yaustar & Leonidas,

I am happy to inform you it perfectly worked. Let me show what I did.
Thank you for the help!!

ViewModeManager.prototype.initialize = function() {
    // Add a <a> to use to download an image file
    var linkElement = document.createElement('a');
    linkElement.id = 'link';

// When the button is clicked, I replaced window.open() with the following codes
        var menuAddress = "https://url.address/";

        // Thanks https://stackoverflow.com/a/44487883
        var link = document.getElementById('link');
        link.setAttribute('href', menuAddress);


Thanks for posting your solution :slight_smile:

1 Like

A post was split to a new topic: Loading scenes issue?