我们都知道您可以使用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)
我想我引用的元素(场景)不是正确的。我已经尝试了“窗口”,但这也没有用。关于我还能尝试什么的任何建议?
谢谢和最好, - 最大
injectInspector()
方法是场景对象上的inspector
component的一部分。在上面发布的代码片段中,this
指的是按钮元素,它没有该方法。要引用该组件,您可以这样做:
var inspector = scene.components.inspector;
// Show inspector immediately.
inspector.injectInspector();
// Show inspector after event.
scene.addEventListener('loaded', function () {
inspector.injectInspector();
});
这段代码也很有用。
function openEditor()
{
window.postMessage('INJECT_AFRAME_INSPECTOR','*');
}
我已将此函数附加到执行上一代码的图像:
<input type="image" src="images/edit.png" width="35" height="35" onclick="openEditor();"/>