JavaScript/userAgent:修订间差异
来自康健生活
| 第18行: | 第18行: | ||
{{leftrightflex|<syntaxhighlight lang="javascript"> | {{leftrightflex|<syntaxhighlight lang="javascript"> | ||
(iframeRef.current.contentWindow || iframeRef.current.contentDocument) | if (Object.defineProperty) { | ||
Object.defineProperty((iframeRef.current.contentWindow || iframeRef.current.contentDocument).navigator, 'userAgent', { | |||
}); | get: function () { | ||
return 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.355'; | |||
} | |||
}); | |||
} else if (Object.prototype.__defineGetter__) { | |||
(iframeRef.current.contentWindow || iframeRef.current.contentDocument).navigator.__defineGetter__('userAgent', function () { | |||
return 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.355'; | |||
}); | |||
} | |||
iframeRef.current.contentWindow.navigator.userAgent</syntaxhighlight>|{{consoleout|<pre> | iframeRef.current.contentWindow.navigator.userAgent</syntaxhighlight>|{{consoleout|<pre> | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.355' | 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.355' | ||
</pre>}}}} | </pre>}}}} | ||
2022年2月24日 (四) 08:41的版本
No categories