javascript - 放大 Iframe 会影响 cordova iOS 应用程序中错误的光标位置

标签 javascript ios html css cordova

我正在使用 Cordova 进行 ios 开发。我使用 iframe 在我的应用程序中打开外部链接。外部页面尺寸很大,为了适应屏幕,我使用了 -webkit-transform scale 属性。一切都很好,它适合屏幕。但问题是,当我选择文本输入时,输入光标(插入符号)开始在文本字段下方某处闪烁。

Image1


请看代码:

index.html:

<div data-role="page" id="personDetailPage">
        <div data-role="header" class="header" >
            <div class="logo"  id="mainScreenLogo"> <img src="" id="headerLogoImg" /> </div>
            <h1 id="personDetailTitle"class="tittle">Person Detail</h1>
            <a href="#main" class="ui-btn-right headerHomeIcon"  data-transition="slide" onclick="formHomeButtonClick();"> <img src="homeIcon.png" class="headerHomeImg" /> </a>    
        </div>
        <div id="iFrameDiv" scrolling="no"> 
            <iframe id="formframe" width="280" height="150" src="form.html" onLoad='fixiFrame();' frameborder="0" ></iframe>  
        </div>

    </div>

表单.html:

<div data-role="page" id="personRegistration" scrolling="no"><br>
        Please Enter the Person Details
        <form id="registrationForm" method="POST" action="https://abe.com/Registration.aspx" onsubmit="return checkform();" >
            <div data-role="fieldcontain" class="ui-hide-label">
                <input type="text" name="name" id="name" value="" placeholder="Name" />
            </div>
            <div data-role="fieldcontain" class="ui-hide-label">                <input type="text" name="email" id="email" value="" placeholder="Email" />
            </div>

            <a href="" id="my-custom-button-registration" data-role="button" data-transition="fade" onclick="return checkform();">Continue</a>
        </form> 
    </div>

而 JS 是:

function fixiFrame() { // set the size of IFrame to the device screen fit
    $("#formframe").width( viewport.width  );
    $("#formframe").height( viewport.height -35- deviceVarient );
}

function resizeIframe(){  //zoom the person registration Iframe upto screen fit it will be called when device ready
    var xaix = viewport.width /widthFactor; // widthFactor is the actual page sixe of external page i.e; abc.com/Registration.aspx
    var yaix = (viewport.height-35- $(".logo").height() ) /heightFactor;
    $('#formframe').css('-webkit-transform', 'scale('+xaix+','+yaix+')');
  $('#formframe').css('-webkit-transform-origin', '0 0');


    //alert('resizeIframe(): xaix = '+xaix+' yaix = '+yaix+' $(.logo).height() = '+$(".logo").height()); //for testing & debugging
}

最佳答案

这是我也面临的一个老问题。我已经研究了我两年前的代码来解决这个问题,这里是解决方案。

我没有使用 iframe 打开外部链接,而是使用了 inAppBrowser 为此打开外部链接。

window.open( encodeURI('externalPage.html') , '_blank', 'location=no','EnableViewPortScale=yes');

现在,'EnableViewPortScale=yes' 选项的作用。它在 CDVInAppBrowser.m 中将 browserOptions.enableviewportscale 设置为 true 用于 UIWebView options 的同一类中的 openInInAppBrowser 方法。即;

self.inAppBrowserViewController.webView.scalesPageToFit = browserOptions.enableviewportscale;

表示上面一行被替换为;

self.inAppBrowserViewController.webView.scalesPageToFit = YES;

UIWebView 实际上有一个属性 scalesPageToFit 考虑到纵横比使页面适合设备宽度.

关于javascript - 放大 Iframe 会影响 cordova iOS 应用程序中错误的光标位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24057963/

相关文章:

iphone - NSFetchRequest 以特定顺序显示结果

html - 如何使用 HTML IFrame 实现自动宽度

html - :hover on circle navigation from angle x to y怎么办

javascript - Arguments 对象是否泄漏?

javascript - NodeJS Try-Catch 不阻塞

javascript - 在不校正网格位置的情况下在一个方向上就地缩放 three.js 几何体

ios - 用核心蓝牙唤醒我的 iOS 应用程序

javascript - ES6 : What does "import $ from ' jquery'"really means?

ios - SIGSEGV 符号仅指向核心类

javascript - 如何用kineticjs制作橡皮擦