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

请看代码:
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>
Run Code Online (Sandbox Code Playgroud)
form.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>
Run Code Online (Sandbox Code Playgroud)
和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
}
Run Code Online (Sandbox Code Playgroud)
这是我也面临的一个老问题。我研究了我两年前的代码来解决这个问题,这是解决方案。
我没有使用iframe来打开外部链接,而是将其嵌入到另一个页面中,而是使用 来inAppBrowser打开外部链接。
window.open( encodeURI('externalPage.html') , '_blank', 'location=no','EnableViewPortScale=yes');
现在,“EnableViewPortScale=yes”选项的作用是什么。其设置browserOptions.enableviewportscale为true在同一个类的方法CDVInAppBrowser.m中使用的。IE;openInInAppBrowserUIWebView options
self.inAppBrowserViewController.webView.scalesPageToFit = browserOptions.enableviewportscale;
Run Code Online (Sandbox Code Playgroud)
这意味着上面的行被替换为;
self.inAppBrowserViewController.webView.scalesPageToFit = YES;
UIWebView实际上有一个属性scalesPageToFit,考虑到宽高比,使页面适合设备宽度。
| 归档时间: |
|
| 查看次数: |
1067 次 |
| 最近记录: |