Issue loading web pages in HTML5 game

I’ve been working on a game that contains links to external pages. sys.open_url(url) is working for loading the proper URL, unfortunately it opens the url in both a new tab and the current tab. This closes the game, and the user has to wait for the game to re-load and restart from the main menu, after going back in their browser. This is obviously not an ideal user experience. Is there any known workaround that can be used until the issue is resolved?

This is happening to me in Chrome, Firefox, IE11, and Microsoft Edge, OS is Windows 10 Home, Defold version is 1.2.83.

This sounds weird, and is obviously not the expected behavior… Maybe @sven knows more about this?

I’ve dug into the issue some more, and have discovered that it specifically happens when popups are blocked on the game’s page. Not sure why it was still opening a new tab (perhaps because it was being run locally), but after putting a build on a server it only loaded in the current page.

I added a window.onbeforeunload event to the html to prevent the page from changing, to get access to the prompt to allow popups on the current page. After enabling popups, the feature seems to work as intended, and the link is just opened in a new tab.

I’m still not certain what’s causing the link to open in the current page when popups are blocked, but it looks like popups are blocked by default in most browsers since there is no active click event when attempting to open the link, despite clicking within the canvas to trigger it.

One final update on this, I found the source of the issue. Within the generated [project title].js file after bundling the project, the function for opening URLs is:

function _dmSysOpenURL(url)
{
var jsurl=Pointer_stringify(url);
if(window.open(jsurl)==null)
{
window.location=jsurl
}
return true
}

So, when the window fails to open the URL, in this case due to a popup blocker, it’s setting the current window’s location. Removal of “window.location=jsurl” fixed the problem.

3 Likes

I believe this bug has an impact on the HTML5 version of Blossom Blast. I remember opening a link, getting a popup blocked, and the game window breaking.

Very nice catch David. I’ll inform the BBS team