Skip to content

Commit

Permalink
Merge pull request #535 from performant-software/feature/permalinks-i…
Browse files Browse the repository at this point in the history
…n-iframe

Allow document permalink feature in iframe embed instances
  • Loading branch information
blms authored Nov 7, 2024
2 parents 5615226 + b3ced32 commit 1f71a05
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions client/src/DocumentViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,17 @@ class DocumentViewer extends Component {
});
}

getDocumentURL(docId) {
const loc = window.location.href.replace(window.location.search, "");
async getDocumentURL(docId) {
let loc = window.location.href.replace(window.location.search, "");
// eslint-disable-next-line no-restricted-globals
const isInIframe = (parent !== window);
const clipboardWrite = await navigator.permissions.query({ name: 'clipboard-write' });
if (isInIframe && clipboardWrite.state === "granted") {
// if in iframe, use parent URL to build document URL
// (check that clipboard write permission is granted to ensure iframe parent URL
// only used here when intentionally enabled)
loc = document.referrer;
}
this.setState((prevState) => ({
...prevState,
documentURL: `${loc}?document=${docId}`
Expand Down
9 changes: 9 additions & 0 deletions public/embed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// include the following code in <script> tags on the same page as an embedded instance
const frame = document.querySelector("iframe");
// allow writing to the clipboard from another domain
frame.setAttribute("allow", "clipboard-write *");
const queryParams = window.location.search;
if (queryParams !== "") {
// pass query params to iframe embed's src attribute (app url)
frame.src = frame.src + queryParams;
}

0 comments on commit 1f71a05

Please sign in to comment.