Javascript Can';t访问Android设备上的Node.childNodes getter
我正在Android设备上调试一个问题。(使用仿真器,但在许多设备中都可以复制)。 我正在使用Android WebView浏览器打开我的页面Javascript Can';t访问Android设备上的Node.childNodes getter,javascript,android,webview,android-webview,Javascript,Android,Webview,Android Webview,我正在Android设备上调试一个问题。(使用仿真器,但在许多设备中都可以复制)。 我正在使用Android WebView浏览器打开我的页面 WebView in com.google.android.gms (39.0.0.0) 我正在选择body元素并成功地读取它的childNodes属性。 但是我在节点.prototype上找不到子节点getter,在prototype链的父节点上也找不到 const el = document.querySelector('body') undefi
WebView in com.google.android.gms (39.0.0.0)
我正在选择body
元素并成功地读取它的childNodes
属性。
但是我在节点.prototype上找不到子节点
getter,在prototype链的父节点上也找不到
const el = document.querySelector('body')
undefined
el instanceof Node
true
el instanceof HTMLBodyElement
true
el instanceof HTMLElement
true
el.childNodes.length
61
Object.getOwnPropertyDescriptor(Node.prototype,'childNodes')
undefined
Object.getOwnPropertyDescriptor(HTMLBodyElement.prototype,'childNodes')
undefined
Object.getOwnPropertyDescriptor(HTMLElement.prototype,'childNodes')
undefined
主体元素原型链:
HTMLBodyElement
HTMLElement
Element
Node
EventTarget
Object
null
childNodes
不作为对象存在。getOwnPropertyDescriptor
在这些节点上都不存在
有什么方法可以让我找到如何将这个childNodes
属性添加到节点。prototype
并获得这个函数吗?我没有找到在这些特定的旧浏览器中获得getter函数的方法(我想是浏览器的一个功能阻止了对它们的访问)
我做了一种变通方法:
const descriptor = Object.getOwnPropertyDescriptor(object, functionName);
if (descriptor?.get) {
return descriptor.get;
}
if (descriptor?.value) {
return descriptor.value;
}
// if no access - just a return a function that returns this property
return function () {
return this[functionName];
};
你好你找到这个问题的解决方案了吗?嘿@Karthikkumar,我没有设法解决它,但找到了某种解决办法。我更新了我的答案,希望能有所帮助。