Skip to content

Commit

Permalink
Disable using the full website in an iframe #446
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacsv committed Jan 27, 2024
1 parent 009e3cb commit c4955b3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
20 changes: 20 additions & 0 deletions sandbox/embed_full_website.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">

<title>Online 3D Viewer</title>

</head>

<body>
<iframe
src="../../website#model=assets/models/solids.obj,assets/models/solids.mtl"
width="640" height="480"
style="border:1px solid #eeeeee;">
</iframe>
</body>

</html>
12 changes: 12 additions & 0 deletions source/website/css/website.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions source/website/index.js
Original file line number Diff line number Diff line change
@@ -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 };
Expand Down Expand Up @@ -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:');

Expand Down

0 comments on commit c4955b3

Please sign in to comment.