Browser "Close" issue

0 favourites
  • 7 posts
From the Asset Store
Firebase: Analytics, Dynamic Links, Remote Config, Performance, Crashlytics on Android, iOS & Web Browser
  • 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 :

    Scripts may close only the windows that were opened by it.[/code:12y266ql]
    
    which point to Browser_plugin.js:
    
    [code:12y266ql]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***
    	};
    	[/code:12y266ql]
    
    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:
    
    [ul]
    	[li]Touch: On touched Sprite -> Browser: Close[/li]
    [/ul]
    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?
  • 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.

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • nice

  • 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.

  • 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? :/

  • 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?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)