I’m working on a Unity webplayer game that needs to open a Javascript popup window when the user clicks a button from inside Unity.
I’ve tried a few different approaches (examples below) but they all seem to get blocked by the web browser. This is happening in Firefox, Safari and Chrome on the Mac, so it seems quite a common problem. The popup window in the final project will be for a Facebook-Connect login, but even the simple examples below just seem to get blocked.
We made a few games before in Flash that open popup windows in the same way and don’t get blocked, so I wonder if there’s something extra I need to do in Unity to make sure the browser recognises the mouse ‘Click Event’ and allows the popup window to be displayed.
I’ve tried using a GUI button with Application.ExternalEval to run some Javascript directly.
Here’s the external Javascript that those last two examples call when it’s embedded on the web-page.
<script language="JavaScript" type="text/javascript">
function OpenPopupWindow()
{
window.open('http://www.google.com', 'open_window');
}
</script>
All three examples cause the browser to block the popup window… If anyone has any suggestions about how we could get this work it would be most appreciated
There is no way to open a window through the popup blocker.
That exactly the reason the popup blocker is there to prevent any kind of unauthorized opening of newe windows / tabs
All you can do is show an iframe / div or alternative redirect the whole page
In the final game, the popup window will be auto-generated by a call to the Facebook Javascript SDK, so I don’t think we would be able to target an iframe or div…
So it looks like it might be best to use a HTML button outside of the Unity webplayer instead, hopefully that would stop the popup getting blocked.
I don’t think that you’re entirely correct dreamora. I’m currently experiencing the same problems as described by MattCoded.
The JS below, when called from Flash, or a simple open window - will open a popup window.
When called from Flash, it has to be from a MouseEvent.CLICK event. Popup blockers will not block this (at least the default ones in Chrome, IE, and FF, perhaps more over-zealous ones will).
It looks like the Unity web plugin somehow doesn’t dispatch the same kind of event to the browser.
Also, many Flash games with FB functionality will open a popup window for authentication, it’s (i believe) the default behaviour with the Adobe ActionScript 3 SDK for Facebook Platform: Google Code Archive - Long-term storage for Google Code Project Hosting. - and I have done this for previous FB-enabled games in Flash.
So my question: Is there any way to get Unity to open a popup window that isn’t blocked? It is 100% possible in both HTML and Flash.