Browser "Close" issue

Discussion and feedback on Construct 2

Post » Wed May 06, 2015 1:34 pm

@Ashley I'm getting a strange issue with Browser plugin and "Close" action.

After triggering "Close" in preview or export nothing happens and Chrome Console (and also FireFox console) gives me :

Code: Select all
Scripts may close only the windows that were opened by it.


which point to Browser_plugin.js:

Code: Select all
Acts.prototype.Close = function ()
   {
      if (this.runtime.isCocoonJs)
         CocoonJS["App"]["forceToFinish"]();
      else if (window["tizen"])
         window["tizen"]["application"]["getCurrentApplication"]()["exit"]();
      else if (navigator["app"] && navigator["app"]["exitApp"])
         navigator["app"]["exitApp"]();
      else if (navigator["device"] && navigator["device"]["exitApp"])
         navigator["device"]["exitApp"]();
      else if (!this.is_arcade && !this.runtime.isDomFree)
         window.close();  ***<- Points here exactly***
   };
   



I though it got to do something with @hmmg LayoutTransition plugin. But then I recreated it in couple of new project, with all plugin I use with my main project (official and third party ones). and it works fine there.

My code is very simple:

- Touch: On touched Sprite -> Browser: Close

nothing more. And for Third party plugins I use only two: LiteTween and LayoutTransition. But like I said it works fine in new projects, only this particular project I'm working on is affected by this.

Any thoughts?
ImageImageImageImage
B
160
S
68
G
43
Posts: 2,603
Reputation: 36,168

Post » Wed May 06, 2015 2:00 pm

This is probably the browser security that avoids been able to close the window programmatically. If you can make another page that you control launch the game then you should be able to close it from the parent. Sending a signal from the game to it.
B
7
S
2
Posts: 15
Reputation: 614

Post » Wed May 06, 2015 7:18 pm

rf900 wrote:This is probably the browser security that avoids been able to close the window programmatically. If you can make another page that you control launch the game then you should be able to close it from the parent. Sending a signal from the game to it.


What do you mean?

It used to work fine on every project in the past. It works fine with every new projects I made. Only in the project I'm currently working on for some reasons this is not working. There is nothing different between this project or any other projects.

It's just a simple action. on sprite touched -> close window


EDIT: hmm and now for some other strange reasons it starts to work properly... without me doing anything :?
ImageImageImageImage
B
160
S
68
G
43
Posts: 2,603
Reputation: 36,168

Post » Wed May 06, 2015 9:17 pm

nice
B
28
S
10
G
9
Posts: 294
Reputation: 7,124

Post » Thu May 07, 2015 9:55 pm

The error message is correct ("Scripts may close only the windows that were opened by it"). Web pages cannot arbitrarily close windows that the user opened. They can only close windows that were opened by a script. I think browsers actually have a more complicated set of rules than that to determine if a page is allowed to close its own window, but basically you can't really rely on it.
Scirra Founder
B
406
S
240
G
91
Posts: 24,771
Reputation: 197,558

Post » Thu May 07, 2015 11:41 pm

Ashley wrote:The error message is correct ("Scripts may close only the windows that were opened by it"). Web pages cannot arbitrarily close windows that the user opened. They can only close windows that were opened by a script. I think browsers actually have a more complicated set of rules than that to determine if a page is allowed to close its own window, but basically you can't really rely on it.


Yes I understand that. But this page we are talking about here is a paged opened by C2 preview (or exported from c2).
And if I can't rely on Browser.Close then how can I exit the app from NW or Crosswalk? :/
ImageImageImageImage
B
160
S
68
G
43
Posts: 2,603
Reputation: 36,168

Post » Mon Aug 10, 2015 2:00 pm

Most browsers now prevent the Window.close method from working in JavaScript if the window wasn't opened by the script for security reasons. The C2 Browser.close therefore doesn't work when exported as html5.

The only way around this would be for C2 to modify the index.html it creates when exporting a game for browsers by executing a window open self before launching the game. It would then be allowed to close this window from the browser I expect.

Perhaps Ashley could confirm and if possible update for a future release?
B
10
S
3
Posts: 87
Reputation: 957


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 3 guests