ForgotPasswordUI::ForgotPasswordUI() : HtmlPage("forget_password") { connect(webFrame, SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject())); ui->forgot_password->setEnabled(false); }
//-------------------------------------------------------- CController::CController(QWebView* view, QObject* parent): QObject(parent), m_view(view) { connect(m_view->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject())); }
UtmpWebView::UtmpWebView():QWebView() { QWebSettings* default_settings = QWebSettings::globalSettings(); default_settings->setAttribute(QWebSettings::JavascriptEnabled,true); default_settings->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled,true); default_settings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled,true); default_settings->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls,true); default_settings->setAttribute(QWebSettings::LocalStorageEnabled,true); default_settings->setAttribute(QWebSettings::JavascriptCanAccessClipboard,true); default_settings->setAttribute(QWebSettings::DeveloperExtrasEnabled,true); default_settings->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); default_settings->setAttribute(QWebSettings::PluginsEnabled,true); default_settings->setAttribute(QWebSettings::JavascriptCanOpenWindows,true); //setContextMenuPolicy(Qt::NoContextMenu); //如何防止框架页面不被业务页面刷掉: //一般业务页面都是套在iframe中的,主要考虑防止target=_top的链接和window.top=''的js事件 //1:如下,可以截获所有链接的点击事件,但信号当中并不能确定这个链接是不是target = _top的 //this->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); //connect(this,SIGNAL(linkClicked(QUrl)),SLOT(openUrl(QUrl))); //2:可以重写QWebPage类的acceptNavigationRequest方法,但只能截获前进、后退、表单提交、刷新等操作,也不行 //3:可以考虑在框架页面中写JS,修改业务页面中的代码(下策) connect(this->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject())); connect(this->page(), SIGNAL(printRequested(QWebFrame*)),this,SLOT(customPrintRequested(QWebFrame*))); this->page()->setForwardUnsupportedContent(true); //这个槽没什么用 connect(this->page(),SIGNAL(downloadRequested(QNetworkRequest)),this,SLOT(download(QNetworkRequest))); connect(this->page(),SIGNAL(unsupportedContent(QNetworkReply*)),this,SLOT(unsupportedContent(QNetworkReply*))); }
ChatView::ChatView(const QByteArray &id, const QString &url, QWidget *parent) : WebView(parent) , m_loaded(false) , m_id(id) , m_lastMessage(0) { setPage(new WebPage(this)); page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); setUrl(QUrl(url)); connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), SLOT(populateJavaScriptWindowObject())); setFocusPolicy(Qt::NoFocus); connect(ChatCore::settings(), SIGNAL(changed(QString,QVariant)), SLOT(settingsChanged(QString,QVariant))); connect(this, SIGNAL(linkClicked(QUrl)), SLOT(openUrl(QUrl))); connect(ChatNotify::i(), SIGNAL(notify(Notify)), SLOT(notify(Notify))); setAcceptDrops(true); setIcons(); createActions(); retranslateUi(); QTimer::singleShot(0, this, SLOT(start())); }
FormExtractor::FormExtractor(QWidget *parent, Qt::WFlags flags) : QWidget(parent, flags) { ui.setupUi(this); ui.webView->setUrl(QUrl("qrc:/form.html")); connect(ui.webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject())); resize(300, 300); }
ChannelsView::ChannelsView(QWidget *parent) : WebView(parent) { connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), SLOT(populateJavaScriptWindowObject())); connect(ChatNotify::i(), SIGNAL(notify(Notify)), SLOT(notify(Notify))); connect(ChatClient::channels(), SIGNAL(channel(QByteArray)), SLOT(channel(QByteArray))); retranslateUi(); }
PluginsView::PluginsView(QWidget *parent) : WebView(parent) { page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); setFocusPolicy(Qt::NoFocus); connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), SLOT(populateJavaScriptWindowObject())); QTimer::singleShot(0, this, SLOT(boot())); }
WebPage::WebPage(QWidget *parent) : QWebPage(parent) { b = (Browser *)parent; connect(mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject()) ); useragent = "FlatTurtle InfoScreenBrowser/" + QCoreApplication::applicationVersion() + " QtWebKit/" + QTWEBKIT_VERSION_STR; }
int FormExtractor::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: submit(); break; case 1: populateJavaScriptWindowObject(); break; default: ; } _id -= 2; } return _id; }
WebPage::WebPage(BatDown* app, QWidget *parent, Qt::WFlags flags) : QWidget(parent, flags), BatDownBase(app) { QFile file; file.setFileName(":/BatDown/jquery.min.js"); file.open(QIODevice::ReadOnly); m_jsLib = file.readAll(); file.close(); file.setFileName(":/BatDown/jquery.json.min.js"); file.open(QIODevice::ReadOnly); m_jsLib.append( file.readAll() ); file.close(); file.setFileName(":/BatDown/yewtic.js"); file.open(QIODevice::ReadOnly); m_jsLib.append(";"); m_jsLib.append( file.readAll() ); m_jsLib.append(";"); file.close(); m_pWebView = new QWebView; m_pAddrBar = new QLineEdit; QVBoxLayout *lay = new QVBoxLayout; //lay->addLayout(btns); //lay->addWidget(m_pAddrBar); lay->addWidget(m_pWebView); connect(m_pWebView, SIGNAL(loadProgress(int)), SLOT(setProgress(int))); connect(m_pWebView, SIGNAL(loadFinished(bool)), SLOT(adjustLocation())); connect(m_pWebView, SIGNAL(loadFinished(bool)), this, SLOT(finishLoading(bool))); connect(m_pWebView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject())); setLayout(lay); setWindowTitle(tr("Web Browser")); //TODO Settings dialog QWebSettings::globalSettings()->setAttribute(QWebSettings::AutoLoadImages, false); }
QWebKitTest::QWebKitTest(QWidget *parent) : QDialog(parent) { m_webObj = new MyWebKit(this); ui->setupUi(this); ui->webView->setUrl((QUrl("qrc:/test.html"))); connect(ui->webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject())); }
MainWindow::MainWindow(const QUrl& url) : m_dongle(new mobot_t) { progress = 0; QFile file; file.setFileName(":/jquery.min.js"); file.open(QIODevice::ReadOnly); jQuery = file.readAll(); jQuery.append("\nvar qt = { 'jQuery': jQuery.noConflict(true) };"); file.close(); //! [1] QNetworkProxyFactory::setUseSystemConfiguration(true); m_interface = new JsInterface(this); //! [2] view = new QWebView(this); view->load(url); connect(view, SIGNAL(loadFinished(bool)), SLOT(adjustLocation())); connect(view, SIGNAL(titleChanged(QString)), SLOT(adjustTitle())); connect(view, SIGNAL(loadProgress(int)), SLOT(setProgress(int))); connect(view, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool))); connect(view->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject())); locationEdit = new QLineEdit(this); locationEdit->setSizePolicy(QSizePolicy::Expanding, locationEdit->sizePolicy().verticalPolicy()); connect(locationEdit, SIGNAL(returnPressed()), SLOT(changeLocation())); QToolBar *toolBar = addToolBar(tr("Navigation")); toolBar->addAction(view->pageAction(QWebPage::Back)); toolBar->addAction(view->pageAction(QWebPage::Forward)); toolBar->addAction(view->pageAction(QWebPage::Reload)); toolBar->addAction(view->pageAction(QWebPage::Stop)); toolBar->addWidget(locationEdit); //! [2] QMenu *viewMenu = menuBar()->addMenu(tr("&View")); QAction* viewSourceAction = new QAction("Page Source", this); connect(viewSourceAction, SIGNAL(triggered()), SLOT(viewSource())); viewMenu->addAction(viewSourceAction); //! [3] QMenu *effectMenu = menuBar()->addMenu(tr("&Effect")); effectMenu->addAction("Highlight all links", this, SLOT(highlightAllLinks())); rotateAction = new QAction(this); rotateAction->setIcon(style()->standardIcon(QStyle::SP_FileDialogDetailedView)); rotateAction->setCheckable(true); rotateAction->setText(tr("Turn images upside down")); connect(rotateAction, SIGNAL(toggled(bool)), this, SLOT(rotateImages(bool))); effectMenu->addAction(rotateAction); QMenu *toolsMenu = menuBar()->addMenu(tr("&Tools")); toolsMenu->addAction(tr("Remove GIF images"), this, SLOT(removeGifImages())); toolsMenu->addAction(tr("Remove all inline frames"), this, SLOT(removeInlineFrames())); toolsMenu->addAction(tr("Remove all object elements"), this, SLOT(removeObjectElements())); toolsMenu->addAction(tr("Remove all embedded elements"), this, SLOT(removeEmbeddedElements())); setCentralWidget(view); setUnifiedTitleAndToolBarOnMac(true); baroboInit(); qDebug() << "App path : " << qApp->applicationDirPath(); }
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); QWebSettings *settings = QWebSettings::globalSettings(); settings->setAttribute(QWebSettings::PluginsEnabled, true);//允许插件 settings->setAttribute(QWebSettings::JavascriptEnabled, true);//JavaScript settings->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);// settings->setAttribute(QWebSettings::JavascriptCanOpenWindows, true); settings->setFontFamily(QWebSettings::FixedFont,"幼圆"); ui->webView->setStyle(new CustomStyle()); ui->webView->load(QUrl("file:///D:/BigData/Qt-Tools/Demo/testwebview/map.html")); // ui->webView->load(QUrl("http://www.yicai.com/video/")); connect(ui->webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject())); }