No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    [capacitor/Android] How to close the window opened by window.open()

    Help
    3
    6
    1647
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      Sfinx last edited by

      App opens the external window for some predefined user iteration and that window must be auto-closed. But what is perfectly works at desktop do not work at under capacitor/Android. If I use onload=“setTimeout(() => window.close(), 5000)” it prints error in console “Scripts may close only the windows that were opened by it”. If I use

      … some Vue…
      let w = window.open()
      setTimeout(() => w.close(), 5000)
      …

      It does nothing. Please help 😉

      1 Reply Last reply Reply Quote 0
      • dobbel
        dobbel last edited by

        @Sfinx

        I think it’s generally better to use Capacitor plugins for that:

        https://capacitorjs.com/docs/apis/browser

        But looking at their docs on how to close the in-app browser:
        “Close an open browser. Only works on iOS and Web environment, otherwise is a no-op” . I read that as it will not work on Android.

        Confirmed close with browser plugin close will not work on Android: https://github.com/ionic-team/capacitor/issues/1414

        Found this also , maybe it will help you:
        https://medium.com/@harshal_59221/window-close-not-working-how-to-redirect-the-parent-window-i-have-got-you-covered-solution-56c63a40f169

        1 Reply Last reply Reply Quote 0
        • S
          Sfinx last edited by

          Solved- the stock cordova iab works perfectly.

          dobbel 1 Reply Last reply Reply Quote 0
          • dobbel
            dobbel @Sfinx last edited by

            @Sfinx
            Great find!

            1 Reply Last reply Reply Quote 0
            • B
              bob12345 last edited by

              @Sfinx could you please tell us how you managed to use the stock cordova iab in a capacitor context? I’ve tried using capacitor’s iab but it doesn’t have event listeners for when the window loads.

              1 Reply Last reply Reply Quote 0
              • S
                Sfinx last edited by Sfinx

                I’ve used stock call:

                if (this.$q.platform.is.capacitor) {
                  return cordova.InAppBrowser.open(url, '_blank', params)
                

                I’ve not needed onload events but needed to auto-close the window after user posts some data at URL. It was not trivial as one tab can’t close other one

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post