javascript - 我可以判断我的 Chrome 扩展程序是否在 Windows 上运行吗?

标签 javascript windows google-chrome google-chrome-extension

在我的 Google Chrome 扩展程序中,我需要将文本复制到剪贴板上,并且我需要知道我的扩展程序是否安装在 Windows 操作系统上。可能吗?

附言。如果是 Windows,那么我会将结束行替换为 "\r\n",这使得多行文本在 Windows 上看起来更好。

最佳答案

至少有两种方式

  1. 您可以简单地依赖 navigator.platform

  2. 更好的选择是使用 Chrome API:chrome.runtime.getPlatformInfo() :

    chrome.runtime.getPlatformInfo(function callback)

    Returns information about the current platform.

    PlatformInfo object 的形式.

    chrome.runtime.getPlatformInfo( function(info) {
      if(info.os == "win") { /* do stuff */ }
    });
    

关于javascript - 我可以判断我的 Chrome 扩展程序是否在 Windows 上运行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25617688/

相关文章:

javascript - 如何下载由 JavaScript 生成的文件,避免自动打开 Chome?

javascript - 在 mongoDB 中使用 (^)carat 进行数字搜索不起作用

javascript - HTML/CSS 标签式导航

javascript - Array.length 在 for 循环中未产生预期结果

c++ - 使用 C++ 从 SID 获取本地 Windows 用户名

windows - 在 Windows 上,如何防止注册表项被修改?

c++ - OpenGL 不让我画东西

google-chrome - Chrome开发者工具接收时间显示错误

javascript - ajax 未检测到图像裁剪

css - 使用 CSS 更改输入的 HTML5 占位符颜色在 Chrome 上不起作用