Working with URLs and navigation
To let users share a link to the current view, use url.set to update the browser address bar. To open another page, such as a help page, use url.open. Both commands are sent to window.parent as window messages.
Synchronize the address bar
type SetURLMessage = { url: { set: string } };
set changes the address bar without navigating, reloading the iframe, or adding a browser history entry. It accepts HTTP or HTTPS URLs within the current app on the host's origin. You can pass the iframe's current URL as-is: DataMiner converts it to the public URL for the draft or published app and keeps the query parameters and fragment.
function reportRoute() {
window.parent.postMessage({ url: { set: window.location.href } }, "*");
}
// Report the initial URL and subsequent hash-based route changes.
reportRoute();
window.addEventListener("hashchange", reportRoute);
// For History API routing, call reportRoute from the router's route-change hook instead.
Open a page
type OpenURLMessage = { url: { open: string; target?: "_blank" | "_self" } };
"_blank"(the default) opens the destination in a new tab or window."_self"opens the destination in the host's current tab, not just the iframe.
The destination can be a same-origin or external HTTP(S) page. Relative URLs are resolved against the host page, not the iframe's asset directory. URLs containing credentials are not allowed.
The browser may still block the new tab.
// Call this when someone selects the Help button.
function openHelp() {
window.parent.postMessage({
url: { open: "https://docs.dataminer.services/", target: "_blank" }
}, "*");
}
Error messages
The host sends errors as { type: "error", message: string } window messages. Successful updates and navigation do not send a reply.
| Message | Meaning |
|---|---|
Invalid URL command. |
The url value is not a command object, the URL is missing or blank, or the object contains fields that do not belong to the selected command. |
URL opening target must be _blank or _self. |
The open command uses an unsupported target. |
Invalid page URL. |
The host could not parse the URL. |
Only HTTP(S) page URLs without credentials are allowed. |
The URL uses another scheme or contains a username or password. |
Only same-origin URLs can update the address bar. |
The set URL points to a different origin. |
Only URLs within the current app can update the address bar. |
The set URL does not point to the current app. |
The page URL could not be updated. |
The host could not resolve the URL to a page it can show in the address bar. |
The page could not be opened. |
The host could not resolve the destination or the browser threw an error while opening it. A blocked pop-up window does not necessarily produce this reply. |