天天看點

【快應用】打開一個H5頁面,能修改标題嗎?

如果使用快應用webview接口打開網頁,無法在快應用中修改标題欄,快應用顯示的标題是來自于網頁中設定的标題,開發者可以在網頁中去修改标題,這樣快應用中就同步修改了。

如果使用快應用web元件加載網頁,開發者可以通過web元件的titlereceive事件監聽網頁标題,然後通過頁面的setTitleBar方法更新标題,核心代碼如下:

<web class="web-page" src="https://www.huawei.com" supportzoom="true" onpagestart="onPageStart" onpagefinish="onPageFinish" ontitlereceive="onTitleReceive" onerror="onError" onmessage="onMessage" onprogress="onProgress" id="web" allowthirdpartycookies="true" multiwindow="true">

</web>

onTitleReceive(e) {

var title = e.title

this.$page.setTitleBar({text: title});

},

欲了解更多更全技術文章,歡迎通路https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh

繼續閱讀