You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS Cordova应用中使用window.open()打开PDF时能否启用旋转?

Can I Enable Screen Rotation When Opening a PDF with window.open() in an iOS Cordova App?

Yep, this is totally possible—but you can’t rely on just the window.open parameters to make it happen. Since your app has global rotation disabled, you’ll need to use a Cordova plugin to dynamically adjust the screen orientation when opening the PDF, then revert it once the viewer closes. Here’s how to do it:

Step 1: Install the Screen Orientation Plugin

First, you’ll need the cordova-plugin-screen-orientation plugin to control orientation dynamically. Install it via the command line:

cordova plugin add cordova-plugin-screen-orientation

Step 2: Unlock Orientation Before Opening the PDF

Before calling window.open, unlock the screen orientation to allow all rotations. Then, open your PDF as usual:

// Unlock orientation to allow all rotations
screen.orientation.unlock();

// Open the local PDF in InAppBrowser
const pdfViewer = window.open('path.to.local.pdf', '_blank', 'EnableViewPortScale=yes,location=no,closebuttoncaption=DONE,toolbarposition=top');

Step 3: Revert to Global Orientation When the Viewer Closes

The window.open call creates an InAppBrowser instance—listen for its exit event to lock the orientation back to your app’s global setting (e.g., portrait) once the user closes the PDF:

pdfViewer.addEventListener('exit', () => {
    // Revert to your app's default locked orientation
    screen.orientation.lock('portrait');
});

Key Notes

  • InAppBrowser Behavior: The InAppBrowser runs in a separate webview, which by default inherits your app’s global orientation settings. The plugin lets you override this temporarily.
  • iOS Compatibility: Test this on your target iOS versions—some older iOS versions may have edge cases with orientation locking in webviews.
  • Config.xml Context: Make sure your global orientation lock is set in config.xml (e.g., <preference name="Orientation" value="portrait" />)—this is what we’re overriding and reverting to.

内容的提问来源于stack exchange,提问作者stg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:32:16