Download lib/postParentMessage.ts from mishig/jepawiki: direct link, hf CLI and curl.
- Browser
- Download file 844 Bytes
-
https://huggingface.co/spaces/mishig/jepawiki/resolve/main/lib/postParentMessage.ts
- Command line
-
hf download hf://spaces/mishig/jepawiki/lib/postParentMessage.ts
-
curl -L -o postParentMessage.ts https://huggingface.co/spaces/mishig/jepawiki/resolve/main/lib/postParentMessage.ts
844 Bytes
| // Utility to post a message to the parent window with custom URLSearchParams. | |
| // Used to sync this iframe's path with the HF Spaces parent URL bar so that | |
| // shareable links to https://huggingface.co/spaces/mishig/jepawiki?path=... | |
| // open the right wiki page. | |
| // | |
| // Pattern borrowed from lerobot-dataset-visualizer. | |
| export function postParentMessageWithParams( | |
| setParams: (params: URLSearchParams) => void, | |
| ) { | |
| if (typeof window === "undefined") return; | |
| if (window.parent === window) return; // not in an iframe | |
| try { | |
| const parentOrigin = "https://huggingface.co"; | |
| const searchParams = new URLSearchParams(); | |
| setParams(searchParams); | |
| window.parent.postMessage( | |
| { queryString: searchParams.toString() }, | |
| parentOrigin, | |
| ); | |
| } catch { | |
| // Ignore cross-origin restrictions or non-iframe contexts. | |
| } | |
| } | |