亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

強制 React-Native webview 將 url 加載為移動設備?

強制 React-Native webview 將 url 加載為移動設備?

千萬里不及你 2022-07-06 09:43:28
在帶有 android studio 的 java 中,我通過添加以下代碼來實現這一點:webView.getSettings().setJavaScriptEnabled(true);webView.getSettings().setLoadWithOverviewMode(true);webView.getSettings().setUseWideViewPort(true);webView.getSettings().setSupportZoom(true);webView.getSettings().setBuiltInZoomControls(true);webView.getSettings().setDisplayZoomControls(false);webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);webView.setScrollbarFadingEnabled(false);但我不知道如何在 React-Native 中做到這一點,我嘗試了一些 css 風格,但沒有成功。這是我在 React 中的 webview:<WebView  ref="WebView"  scalesPageToFit={true}  onLoadStart={this.onLoadStart}  onLoadEnd={this.onLoadEnd}  source = {{ uri:this.props.navigation.getParam('main_url',   'https://xxxx.xxx/')}}  style={{backgroundColor: 'transparent',width: '100%'}}/>:null}
查看完整描述

2 回答

?
茅侃侃

TA貢獻1842條經驗 獲得超22個贊

使用用戶代理。


注意:這曾經僅適用于 Android。對于 iOS,您可以使用此鏈接Change User-Agent 現在它似乎適用于 iOS 和 android


<Webview

  userAgent="Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3714.0 Mobile Safari/537.36"

/>


查看完整回答
反對 回復 2022-07-06
?
慕的地6264312

TA貢獻1817條經驗 獲得超6個贊

受 Sanyam 評論的啟發,您需要設置用戶代理以將其加載為移動設備:


<WebView

    userAgent={DeviceInfo.getUserAgent() + " - MYAPPNAME - android "}

    {...otherProps}

/>


查看完整回答
反對 回復 2022-07-06
  • 2 回答
  • 0 關注
  • 100 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號