我们都知道您可以使用 strg+alt+i 启动检查器,但我现在正在尝试向我的用户界面添加一个按钮来执行相同的操作:
function customEnterInspector () {
var scene = document.querySelector('a-scene');
if (scene) {
if (scene.hasLoaded) {
this.injectInspector();
} else {
scene.addEventListener('loaded', this.injectInspector());
}
}
}
$( "#intoinspector" ).click(function() {
customEnterInspector();
});
但是,我确实收到错误:
Uncaught TypeError: this.injectInspector is not a function
at customEnterInspector (index.html:925)
at HTMLAnchorElement.<anonymous> (index.html:933)
at HTMLAnchorElement.dispatch (jquery-3.1.1.min.js:3)
at HTMLAnchorElement.q.handle (jquery-3.1.1.min.js:3)
我认为我引用的元素(场景)不正确。我已经尝试过“窗口”,但这也不起作用。关于我还可以尝试什么有什么建议吗?
谢谢,最好的, - 最大
最佳答案
这段代码也运行得很好。
function openEditor()
{
window.postMessage('INJECT_AFRAME_INSPECTOR','*');
}
我已将此函数附加到执行前面代码的图像:
<input type="image" src="images/edit.png" width="35" height="35" onclick="openEditor();"/>
关于javascript - Mozilla AFRAME a-frame 通过按钮单击而不是击键启动检查器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41674843/