From c4955b39de5202d71d019984243011355051a006 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Sat, 27 Jan 2024 12:01:05 +0100 Subject: [PATCH] Disable using the full website in an iframe #446 --- sandbox/embed_full_website.html | 20 ++++++++++++++++++++ source/website/css/website.css | 12 ++++++++++++ source/website/index.js | 13 +++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 sandbox/embed_full_website.html diff --git a/sandbox/embed_full_website.html b/sandbox/embed_full_website.html new file mode 100644 index 00000000..6547e647 --- /dev/null +++ b/sandbox/embed_full_website.html @@ -0,0 +1,20 @@ + + + + + + + + Online 3D Viewer + + + + + + + + diff --git a/source/website/css/website.css b/source/website/css/website.css index 0f4fb90e..ddd4d33d 100644 --- a/source/website/css/website.css +++ b/source/website/css/website.css @@ -130,6 +130,18 @@ div.intro div.intro_file_formats a:hover background: var(--ov_outline_button_hover_color); } +div.noembed +{ + text-align: center; + padding: 10px; +} + +div.noembed a +{ + padding: 10px 0px; + display: block; +} + div.main { overflow: hidden; diff --git a/source/website/index.js b/source/website/index.js index cd15e5c8..d634369a 100644 --- a/source/website/index.js +++ b/source/website/index.js @@ -1,11 +1,12 @@ import { SetExternalLibLocation } from '../engine/io/externallibs.js'; +import { Loc } from '../engine/core/localization.js'; +import { AddDiv, AddDomElement } from '../engine/viewer/domutils.js'; import { Embed } from './embed.js'; import { Website } from './website.js'; import { SetEventHandler, HandleEvent } from './eventhandler.js'; import { PluginType, RegisterPlugin } from './pluginregistry.js'; import { ButtonDialog, ProgressDialog } from './dialog.js'; import { ShowMessageDialog } from './dialogs.js'; -import { Loc } from '../engine/core/localization.js'; import * as Engine from '../engine/main.js'; export { Engine }; @@ -48,8 +49,16 @@ export function RegisterToolbarPlugin (plugin) export function StartWebsite (externalLibLocation) { SetExternalLibLocation (externalLibLocation); - window.addEventListener ('load', () => { + if (window.self !== window.top) { + let noEmbeddingDiv = AddDiv (document.body, 'noembed'); + AddDiv (noEmbeddingDiv, null, Loc ('Embedding Online 3D Viewer in an iframe is not supported.')); + let link = AddDomElement (noEmbeddingDiv, 'a', null, Loc ('Open Online 3D Viewer')); + link.target = '_blank'; + link.href = window.self.location; + return; + } + document.getElementById ('intro_dragdrop_text').innerHTML = Loc ('Drag and drop 3D models here.'); document.getElementById ('intro_formats_title').innerHTML = Loc ('Check an example file:');