Using Three.js to generate a CSS3DObject containing an HTML iframe from a different origin results in an error

The HTML code snippet below incorporates Three.js for creating a 3D scene and rendering it with CSS. It includes two separate HTML files: index.html and moo.html.

<!doctype html>
<html lang="en>
<body>

<script src="js/Three.js"></script>
<script src="js/CSS3DRenderer2.js"></script>
<script src="js/THREEx.WindowResize.js"></script>


<div id="ThreeJS" style="position: absolute; left: 0px; top: 0px"></div>
<script>
    var container, scene, camera, renderer, controls, stats;
    var rendererCSS;

    init();
    animate();

    function init() {
        // Initialization of the scene, camera, and renderer
        // Creation and positioning of an iframe within the scene
    }

    function animate() {
        // Function to handle animation through rendering
    }

    function render() {
        // Render the CSS3D and WebGL scenes
    }
</script>

</body>
</html>

moo.html:

<!DOCTYPE html>
<html>
<body>
<h1>hello world!</h1>
</body>
</html>

This code demonstrates the use of iframes in a Three.js environment where changing the source link can result in different visual outputs.

It is possible to create cross-domain iframes, which allows you to embed content from external sources securely.

Answer №1

A solution using an iFrame is possible, but it may not be the most efficient option in THREEJS. Consider exploring alternative methods that could provide faster and more effective results.

In order to see successful outcomes, you will need to set up a server on your localhost or use a development server. I have created a JSFIDDLE with code that should work on a server for reference.

LINK: http://jsfiddle.net/vnjn6mnL/19/

The concept is straightforward: retrieve data from a valid JSON object without relying on jQuery to parse a remote file (although you can).

You can then iterate over the JSON object using a for loop:

for (var i = 0; i < json.projectData.length; i ++)

This code can be found on line 125 of the fiddle. Below the loop, you will see how to extract information from the JSON object:

// Individual Element Creation
var element = document.createElement( 'div' );
element.className = 'element';

// Individual Element Picture Creation
var logo = document.createElement( 'div' );
logo.className = 'logo';
logo.innerHTML = "<img src='" +json.projectData[i].projectLogo + "'>";                  

element.appendChild( logo );

Using a JSON object provides flexibility in presenting data, especially when working directly with CSS elements like images.

If dealing with JSON objects seems overwhelming, consider this workflow:

Generate a JSON object programmatically using: . The link contains the logic used to generate data for the example.

Verify the validity of the JSON object using an online JSON validator. Search "JSON Validator" on Google for reliable options.

Once you confirm its validity, incorporate it into your JavaScript scene by encapsulating it within a global variable tag. Refer back to the provided Fiddle for additional guidance.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using the Proper 'this' Reference Without Repeating 'this' in Nested Functions

I am facing an issue in my class where I have multiple methods and properties. One of these methods contains a setTimeout() function as follows: function myClass() { this.some_property = "test"; this.PrintOnTimeout = function() { // I thou ...

How to Implement a Dropdown Menu in HTML and CSS for Navigation Bars

Currently, I am in the process of creating a website at www.bossfakeid.co.uk. I am looking to add a dropdown menu to the "Products" section of the navbar. I found a dropdown menu solution that I would like to implement from this link: http://codepen.io/wil ...

Collect data from a third-party website that necessitates the activation of JavaScript

Given that phantomjs has been abandoned, I am exploring alternative methods. For instance, using chrome-webdriver may not be ideal as it cannot operate on a remote host like heroku. Is there a way to scrape a website that relies on JavaScript being activa ...

What is the best way to ensure the div stays in sync with scrolling?

Trying to synchronize two divs while scrolling. Essentially, I have a page scroll and want to fix the second div when it reaches the top. Please refer to the gif icon attached for clarification. You can view my progress so far here. The current issue in ...

Displaying images in a React app using Node.js

I receive the image from the user as formdata Here is how I structured the Schema for the image The Image has been successfully stored in Monogodb This is my process of fetching image information using Axios I implement code for rendering the image on the ...

Speed up the opening and closing of a div element on mouse hover

Looking to create a smooth delay for opening and closing a div when mouse hover. Here is the code I have: function show_panel1() { document.getElementById('hoverpanel1').style.display="block"; } function hide_panel1() { document.getElementByI ...

Flexbox can be incorporated with a slide down animation to create

Currently I am attempting to replicate the "slideUp" and "slideDown" features in jQuery while utilizing a flexbox for display! jQuery.fn.toggleFlexbox = function() { var elm = $(this[0]); if(elm.css('display') === "none"){ elm.cs ...

Align the reposition button with the pagination in the datatables

I am looking to adjust the placement of my buttons. The buttons in question are for comparison, saving layout, and printing. I would like them to be inline with the pagination, as I am using datatables here. <table id="sparepart_id" cellspacing="0" ...

Is there a way to detect when the user closes a tab or browser in HTML?

I am currently developing a web application using the MVC architecture and I need to find a way to detect when a user closes their browser tab so that I can destroy their session. My tech stack includes jsp (html, js) and java. Any suggestions on how to ...

Exploration of jQuery Dropdown Menus

Encountering a problem with my dropdown menu. Check out the code here: http://jsfiddle.net/xY2p6/1/ It seems like a simple issue that I can't figure out, but as shown in the link, the functionality is not working properly. I need help linking the hid ...

What is the best way to combine data from two rows into one row?

Can someone help me with merging 2 sets of Line data into a single row for each entry? For example, the 'Green Bay Packers @ Chicago Bears' row should display '+3.5000 and -3.5000', while 'Atlanta @ Minnesota' should show &apo ...

Generating automatic slugs in Django is a useful feature to simplify URL generation

I'm in the process of creating a blog and I am looking for a way to automatically generate the slug so that the URL can be based on the article title. Thank you very much ...

Load a form using ajax and submit it using jQuery

For a while now, I have been facing challenges in figuring out what's going wrong with my code. The issue arises when I try to submit a form using jQuery that was loaded through ajax. The form loads perfectly fine within a div after invoking the ajax ...

Utilizing extra CSS for a full-width Wordpress featured image makes for a visually stunning design

Is there a way to customize the CSS of a featured image in Wordpress Version 5.9.2 to appear full width? Currently, the image has a large margin and does not fill the entire width as seen on the page below: I attempted to achieve this by adding code to th ...

A versatile HTML5 element that can be placed anywhere on the webpage

I am currently developing a library that assists in dynamically loading design. For example: A.EJS This is the a.ejs file B.EJS <b><%= phoxy.DeferRender('a', {}) %></b> Will be presented as <b><div id="phoxy_defe ...

Utilizing Multi External CDN JavaScript File with Vue CLI Component: A Comprehensive Guide

I've been trying different methods to include external JS files in a Vue Component, such as using mounted() and created(), but unfortunately, none of them have worked for me so far. I'm not sure where I'm going wrong. Any assistance would be ...

Setting up server-side CORS in ExpressJS will not include the "Access-Control-Allow-Origin" header

Looking to tackle a CORS request for an ExpressJS server, which is new territory for me. Despite encountering similar issues in the past, I can't seem to pinpoint the problem this time around. It appears that the required headers may not be in the cor ...

Encountering an unexpected Action Controller error while using Rails 4 and implementing unobtrusive JavaScript with AJAX requests

My current setup looks like this: In the uploads_controller.rb file: class UploadsController < ApplicationController before_action :set_upload, only: [:show, :edit, :update, :destroy] # GET /uploads def index @uploads = Upload.all ...

Implementing onClick event handling in Material UI components using Typescript

I am attempting to pass a function that returns another function to material UI's onTouchTap event: <IconButton onTouchTap={onObjectClick(object)} style={iconButtonStyle} > <img alt={customer.name} className="object-img" src={obj ...

Pressing the submit button in the Material UI table clears all selected checkboxes

Take a look at this code snippet: https://jsfiddle.net/aewhatley/Lkuaeqdr/1/. My objective is to construct a table with a submit button utilizing Material-UI components. const { Table, TableHeader, TableHeaderColumn, TableBody, TableRow, Table ...