javascript 如何检查移动 Safari 的窗口对象?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6206568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 19:51:15  来源:igfitidea点击:

How can I inspect the window object for mobile safari?

javascriptjqueryiphonemobilesafari

提问by fancy

How can I inspect the window object for mobile safari?

如何检查移动 Safari 的窗口对象?

Or more specifically window.navigator - trying to convert to string doesn't work and I can't explore it within the console either.

或者更具体地说 window.navigator - 尝试转换为字符串不起作用,我也无法在控制台中探索它。

Thanks!

谢谢!

EDIT:

编辑:

console.log(window.navigator);

console.log(window.navigator);

console.log(String(window.navigator));

console.log(String(window.navigator));

console.log(JSON.stringify(window.navigator));

console.log(JSON.stringify(window.navigator));

console.log(window.navigator.serialize());

console.log(window.navigator.serialize());

Also tried sending all these variations over the socket to the server and logging them there.

还尝试通过套接字将所有这些变化发送到服务器并将它们记录在那里。

Output is either [object Navigator], "{}", or nothing

输出或者是[object Navigator]"{}"或什么

采纳答案by Teddy

I like jsconsole.com.

我喜欢 jsconsole.com。

Also, you can use the json2.js library (https://github.com/douglascrockford/JSON-js), which will give you JSON.stringify() function.

此外,您还可以使用 json2.js 库 (https://github.com/douglascrockford/JSON-js),它将为您提供 JSON.stringify() 函数。

console.log(JSON.stringify({a:'a',b:'b'});

回答by Blaine

Update!!!On OS X you can use the Safari web inspector on the iOS Simulator AND iOS 6 devices.

更新!!!在 OS X 上,您可以在 iOS 模拟器和 iOS 6 设备上使用 Safari Web 检查器。

  1. First enable the Developer menu in Safari.
  2. Next, enable remote debugging on your iOS device (or simulator).

    Settings > Safari > Advanced > Web Inspector (ON)
    
  3. Go back to Safari on your device.
  4. Go back to your computer, click the Developer menu, and select your device (e.g. iPhone Simulator, iPhone)
  1. 首先在 Safari 中启用开发者菜单。
  2. 接下来,在您的 iOS 设备(或模拟器)上启用远程调试。

    Settings > Safari > Advanced > Web Inspector (ON)
    
  3. 在您的设备上返回 Safari。
  4. 返回您的计算机,单击开发人员菜单,然后选择您的设备(例如 iPhone 模拟器、iPhone)

Note: You'll see your device in the Developer menu ONLY when Safari is active and running.

注意:只有当 Safari 处于活动状态并正在运行时,您才会在“开发人员”菜单中看到您的设备。

Enjoy!

享受!

回答by Mladen Janjetovic

You can also use this to activate Firebug on your device. Took me a lot of time to find this.

您还可以使用它来激活设备上的 Firebug。我花了很多时间才找到这个。

http://martinkool.com/post/13629963755/firebug-on-ipad-and-iphone

http://martinkool.com/post/13629963755/firebug-on-ipad-and-iphone

回答by Marcel Korpel

Those outputs look entirely correct. E.g., when I ask for the string version of window.navigator, I correctly get

这些输出看起来完全正确。例如,当我要求 的字符串版本时window.navigator,我正确地得到

console.log(String(window.navigator));
"[object Navigator]"

On the other hand, when I ask for a specific value, I get (in Chromium):

另一方面,当我要求一个特定的值时,我得到(在 Chromium 中):

console.log(window.navigator.userAgent);
"Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.71 Safari/534.24"

And when I try to enumerate all items, I get

当我尝试枚举所有项目时,我得到

for (var i in window.navigator) console.log(i);
language
product
mimeTypes
appVersion
plugins
onLine
platform
vendor
appCodeName
cookieEnabled
geolocation
appName
productSub
userAgent
vendorSub
javaEnabled
getStorageUpdates

(please be aware that in the above line of code I didn't check for hasOwnProperty, which you normally should use when iterating over object elements).

(请注意,在上面的代码行中我没有检查hasOwnProperty,通常在迭代对象元素时应该使用它)。

回答by Jonathan.

There isn't a Developer Tools window in mobile safari. There is a Debug Console, which will report errors in javascript, html and css, but it is nowhere near Developer Tools you'll find in a desktop browser. This debug console doesn't allow input of javascript (although this can be done in the address bar, eg javascript:alert("hi");)

移动 safari 中没有开发人员工具窗口。有一个调试控制台,它将报告 javascript、html 和 css 中的错误,但它与您在桌面浏览器中找到的开发人员工具相去甚远。这个调试控制台不允许输入 javascript(虽然这可以在地址栏中完成,例如javascript:alert("hi");

To enable the Debug Console, open the settingsapp, go to the Safarimenu, then Developer, and then turn on the debug console. Go back to Safari, scroll to the top of the page and it will be obvious what to do to get to the Debug Console.

要启用调试控制台,请打开设置应用程序,转到Safari菜单,然后是Developer,然后打开调试控制台。返回 Safari,滚动到页面顶部,很明显要做什么才能进入调试控制台。