Merge pull request #11837 from Snuffleupagus/webviewerloaded-top
Always attempt to dispatch the "webviewerloaded" event at the embedding `document` (PR 10318 follow-up, issue 11829)
This commit is contained in:
commit
e23d5f6022
@ -211,8 +211,20 @@ function webViewerLoad() {
|
||||
// set various `AppOptions`, by dispatching an event once all viewer
|
||||
// files are loaded but *before* the viewer initialization has run.
|
||||
const event = document.createEvent("CustomEvent");
|
||||
event.initCustomEvent("webviewerloaded", true, true, {});
|
||||
document.dispatchEvent(event);
|
||||
event.initCustomEvent("webviewerloaded", true, true, {
|
||||
source: window,
|
||||
});
|
||||
try {
|
||||
// Attempt to dispatch the event at the embedding `document`,
|
||||
// in order to support cases where the viewer is embedded in
|
||||
// a *dynamically* created <iframe> element.
|
||||
parent.document.dispatchEvent(event);
|
||||
} catch (ex) {
|
||||
// The viewer could be in e.g. a cross-origin <iframe> element,
|
||||
// fallback to dispatching the event at the current `document`.
|
||||
console.error(`webviewerloaded: ${ex}`);
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
pdfjsWebApp.PDFViewerApplication.run(config);
|
||||
|
Loading…
x
Reference in New Issue
Block a user