V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
deben
V2EX  ›  问与答

请教 phantomjs 问题, 怎么设置屏幕的分辨率呢? (并非浏览器显示尺寸,而是屏幕分辨率)

  •  
  •   deben · 2016-02-10 20:10:42 +08:00 · 3537 次点击
    这是一个创建于 2969 天前的主题,其中的信息可能已经有所发展或是发生改变。
    页面用 JS 来获取客户端屏幕尺寸, 一直显示是 1024*768
    设置 viewportSize 只能调整浏览器的尺寸, 而不是终端设备屏幕尺寸.

    有了解 phantomjs 的同学吗? 求救!

    (比如简单的 JS 代码: screen.width screen.height)
    3 条回复    2016-02-13 01:08:46 +08:00
    Archangel_SDY
        1
    Archangel_SDY  
       2016-02-10 22:23:35 +08:00
    这个和 PhantomJS 其实关系不大, WebKit 里直接调的 Qt 的 API 获取物理屏幕的分辨率,恐怕你只靠 PhantomJS 的 API 是搞不定的.

    https://github.com/Vitallium/qtwebkit/blob/e7b74331d695bfa8b77e39cdc50fc2d84a49a22a/Source/WebCore/platform/qt/PlatformScreenQt.cpp#L90
    chemzqm
        2
    chemzqm  
       2016-02-11 00:35:22 +08:00
    用 js hack 原生对象,例如

    Object.defineProperty(screen,'height', {value:300})
    deben
        3
    deben  
    OP
       2016-02-13 01:08:46 +08:00
    @Archangel_SDY @chemzqm 多谢二位的回答

    最终解决方法为: 在 onInitialized 的时候, 通过 evaluate 方法, 设置了 window.screen.
    算是曲线解决问题了...
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   980 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 20:11 · PVG 04:11 · LAX 13:11 · JFK 16:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.