javascript - 在新窗口中加载新的 A 框架场景

标签 javascript aframe

当您单击按钮时,我正在尝试在新窗口中加载新场景。为此,当您单击 HTML 按钮时,它会打开一个新窗口。

对于这个新窗口,我有以下代码:

let newWindow = window.open();    // Open a new window 

let newHead = newWindow.document.head;
let newBody = newWindow.document.body;

let charset = document.createElement('meta');
charset.setAttribute('charset', 'UTF-8');

let aframe_script_1 = document.createElement('script');
aframe_script_1.setAttribute('src','https://aframe.io/releases/0.9.0/aframe.min.js');

let jquery_script_1 = document.createElement('script');        
jquery_script_1.setAttribute('src','https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js');

newHead.appendChild(charset);
newHead.appendChild(aframe_script_1);
newHead.appendChild(jquery_script_1);


let escena2 = document.createElement ('a-scene');

entidadBox2.setAttribute("id","box");
let geometry = "primitive:box";
entidadBox2.setAttribute("geometry","primitive:box");
entidadBox2.setAttribute("color", "#EF2D5E");
entidadBox2.object3D.position.set(0, 1.25, -5);

escena2.appendChild(entidadBox2);

newBody.appendChild(escena2);

但是,即使新的 HTML 包含场景和框,场景也不会在新窗口中加载。

你知道我该怎么做吗?

最佳答案

所以基本上,使用子文档并在加载后添加元素

let newWindow = window.open();    // Open a new window 

newWindow.onload = function () {
    let doc = newWindow.document;
    let newHead = newWindow.document.head;
    let newBody = newWindow.document.body;

    let charset = doc.createElement('meta');
    charset.setAttribute('charset', 'UTF-8');

    let aframe_script_1 = doc.createElement('script');
aframe_script_1.setAttribute('src','https://aframe.io/releases/0.9.0/aframe.min.js');

    let jquery_script_1 = doc.createElement('script');        
jquery_script_1.setAttribute('src','https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js');

    newHead.appendChild(charset);
    newHead.appendChild(aframe_script_1);
    newHead.appendChild(jquery_script_1);

    let escena2 = doc.createElement ('a-scene');

    entidadBox2.setAttribute("id","box");
    let geometry = "primitive:box";
    entidadBox2.setAttribute("geometry","primitive:box");
    entidadBox2.setAttribute("color", "#EF2D5E");
    entidadBox2.object3D.position.set(0, 1.25, -5);

    escena2.appendChild(entidadBox2);

    newBody.appendChild(escena2);
}

关于javascript - 在新窗口中加载新的 A 框架场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60371810/

相关文章:

javascript - Reactjs - 在移动浏览器 (Chrome/Safari) 中隐藏地址栏

aframe - A 形框架 - glTF - 未找到资源

javascript - 多个单选按钮组

javascript - javascript 中的纯数字文本框验证

javascript - Electron -将参数从main.js传递到html

audio - 在一个帧中,当新声音开始播放时,如何停止所有声音?

javascript - 是否可以使用 AR.js 在网络上进行增强现实扩展跟踪?

javascript - Dojo 教程 - 业务应用程序架构

reactjs - react NotFoundError : Failed to execute 'insertBefore' on 'Node' : The node before which the new node is to be inserted is not a child of this node

javascript - 来自 Javascript 的双面 a-frame a-panel