infor-cloud / m3-h5-sdk

https://infor-cloud.github.io/m3-h5-sdk/
34 stars 20 forks source link

Close the H5 tab running the H5 SDK app #62

Closed chrisonline closed 3 years ago

chrisonline commented 4 years ago

Is there a way to close the H5 tab via code where the H5 SDK app is running?

anhallbe commented 4 years ago

I don't think there's a H5 API for this. It would have to be added.

Just for clarification, you want the app inside the tab to close itself, right? Or do you want to close it from some external app/script, e.g H5 script?

It would be pretty useful to have more control over the H5 tab from the app itself. I could imagine something like this:

interface H5Tab {
  getTitle(): string;
  setTitle(title: string): void;
  close(): void;
  focusedOrActiveOrSomething$: Observable<boolean>;
}

...but this is not part of the SDK (yet).

anhallbe commented 4 years ago

This will be added to a later version of H5 (Most likely CE only).

Wrappers for the API may be added to the this SDK later as well. Keeping the issue open in the meantime.

chrisonline commented 3 years ago

Just for clarification, you want the app inside the tab to close itself, right? Or do you want to close it from some external app/script, e.g H5 script?

I want to close it from the H5 App, so the user does not need to tap on "x" at the to.

anhallbe commented 3 years ago

Update: You can send the following message to H5 from inside the app:

const message = JSON.stringify({
  type: "unload-tab",
  data: {
    tabId: document.body.getAttribute("h5tab"),
  }
});
window.parent.postMessage(message)

The "H5Tab" interface may still be added in the future, but I'm closing this ticket.