在QML webview中使用alert及confirm Dialogs
来源:互联网 发布:四川大学口腔医学知乎 编辑:程序博客网 时间:2024/05/21 11:28
我们可以在QML应用中直接使用QML WebView来装载我们的HTML应用,但是如果我们的HTML文件中使用到alert及confirm,我们的应用可能并不能弹出我们需要的alert及confirm。这时,我们需要对WebView中的alertDialog及confirmDialog进行设计才可以起到作用。
我们在下面来展示如何去做:
index.html
<html> <head> <script type="text/javascript"> <!-- function getConfirmation(){ var retVal = confirm("Do you want to continue ?"); if( retVal == true ){ return true; } else{ return false; } } //--> <!-- function getAlert(){ alert("This is cool!"); } //--> <!-- function getPrompt(){ var retVal = prompt("Enter your name : ", "your name here"); // console.log("retVal: + " + retVal); } //--> </script> </head> <body> <p>Click the following button to see the result: </p> <form> <input type="button" value="Alert Dialog" onclick="getAlert();" /> <br> <input type="button" value="Confirm Dialog" onclick="getConfirmation();" /> <br> <input type="button" value="Prompt Dialog" onclick="getPrompt();" /> </form> </body></html>
Main.qml
import QtQuick 2.0import Ubuntu.Components 1.1import Ubuntu.Web 0.2import Ubuntu.Components.Popups 1.0/*! \brief MainView with a Label and Button elements.*/MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "webviewdialog.liu-xiao-guo" /* This property enables the application to change orientation when the device is rotated. The default is false. */ //automaticOrientation: true // Removes the old toolbar and enables new features of the new header. useDeprecatedToolbar: false width: units.gu(60) height: units.gu(85) Page { title: i18n.tr("webviewdialog") Component { id: confirmDlg Dialog { title: i18n.tr("JavaScript Confirmation") Button { text: i18n.tr("OK") onClicked: model.accept() } Button { text: i18n.tr("Cancel") onClicked: model.reject() } Component.onCompleted: show() } } Component { id: alertDlg Dialog { title: model.message Button { text: i18n.tr("OK") onClicked: model.accept() } Component.onCompleted: show() } } Component { id: promptDlg Dialog { TextField { id: input text: model.defaultValue onAccepted: model.accept(input.text) } Button { text: i18n.tr("OK") color: "green" onClicked: model.accept(input.text) } Button { text: i18n.tr("Cancel") color: UbuntuColors.coolGrey onClicked: model.reject() } Binding { target: model property: "currentValue" value: input.text } Component.onCompleted: show() } } WebView { anchors.fill: parent url: "www/index.html" confirmDialog: confirmDlg alertDialog: alertDlg promptDialog: promptDlg } }}
在这里,我们对alertDialog及confirmDialog进行了初始化,这样当我们在index.html中使用alert及confirm时,我们可以得到我们需要的Dialog:
整个项目的源码在:https://github.com/liu-xiao-guo/webviewdialog
0 0
- 在QML webview中使用alert及confirm Dialogs
- 使用jQuery Alert Dialogs Plugin代替JS的confirm时在列表控件中实现
- Query Alert Dialogs (Alert, Confirm, Prompt)
- 在SilverLight 2中使用弹出式对话框(Alert、Confirm)
- webview alert confirm 重写
- 在Android的webview中定制js的alert,confirm和prompt对话框的方法
- 在Android的webview中定制js的alert,confirm和prompt对话框的方法
- 在Android的webview中定制js的alert,confirm和prompt对话框的方法
- 在Android的webview中定制js的alert,confirm和prompt对话框的方法
- 在Android的webview中定制js的alert,confirm和prompt对话框的方法
- 在Android的webview中定制js的alert,confirm和prompt对话框的方法
- 在Android的webview中定制js的alert,confirm和prompt对话框的方法
- alert、confirm、prompt的区别及使用
- WebView使用小结----提示框的使用Alert,Confirm,Prompt.
- iPhone and iPad JavaScript dialogs (alert, confirm, prompt) and windows
- JavaScript中confirm,alert,prompt的用法及返回值
- JavaScript中confirm,alert,prompt的用法及返回值
- 在WebBrowser控件中阻止alert,confirm对话框
- deep learning入门实验(1)---minist
- JAVA反射
- poj-2996&2993 Help Me with the Game
- phantomjs 抓取、截图中文网站乱码的问题的解决
- vs2005(或是2010)下oracle 10g oci编程环境的配置
- 在QML webview中使用alert及confirm Dialogs
- 算法速成(5)栈
- C++之set
- HDU 5336 XYZ and Drops(BFS)
- 用智能指针管理容器及内存紧凑
- [Android][细节][布局]View的getDrawingCache()方法不会在bitmap的透明区域绘制该View下方的View
- ubuntu unzip解压时提示错误 解决方法
- 南邮 OJ 1016 求幂
- extjs类继承图之数据源(2)