CefView / QCefView

A Qt Widget encapsulated CEF view based on QWidget
https://cefview.github.io/QCefView/
GNU Lesser General Public License v2.1
502 stars 133 forks source link

新版本为何没有onBeforeBrowse重载了, 想要阻断redirect需要怎么操作呢 #415

Open liaowubinf opened 3 weeks ago

liaowubinf commented 3 weeks ago

如题 新版本为何没有onBeforeBrowse重载了, 想要阻断redirect需要怎么操作呢

L-Super commented 2 weeks ago

参考文档:https://cefview.github.io/QCefView/zh/docs/reference/QCefView#class_q_cef_view_1a0aa0b257b5383428569d46c39d4003a2

https://cefview.github.io/QCefView/zh/docs/reference/QCefView#class_q_cef_view_1aff9055d5f9f773c2582c20b4bdf0cd33

liaowubinf commented 2 weeks ago

参考文档:https://cefview.github.io/QCefView/zh/docs/reference/QCefView#class_q_cef_view_1a0aa0b257b5383428569d46c39d4003a2

https://cefview.github.io/QCefView/zh/docs/reference/QCefView#class_q_cef_view_1aff9055d5f9f773c2582c20b4bdf0cd33

这个只能阻断弹窗,如果是修改window.location.href这样的情况不会进入到这两个回调

L-Super commented 2 weeks ago

看了一下相关提交,没有onBeforeBrowser接口。

liaowubinf commented 2 weeks ago

看了一下相关提交,没有onBeforeBrowser接口。

是的, 我也没找到, 但最近接手的一个老项目, 里面的qcefview.h里面有这个 ///

/// Gets called before the main browser redirect url /// /// /// /// /// /// virtual bool onBeforeBrowse(qint64 frameId, const std::string& url, const bool user_gesture, const bool is_redirect);

我在将老项目升级为64位时发现新版没有这个方法了

liaowubinf commented 2 weeks ago

看了一下相关提交,没有onBeforeBrowser接口。

想问下没有这个onBeforeBrowse方法, 还有别的方式能拦截window.location.href这种redirect吗

L-Super commented 2 weeks ago

先确认一下,你是使用的哪个仓库? https://github.com/CefView/CefViewCore/blob/fe335787e8ce5d9bf719617a248c5a9bf7e8e35c/include/CefViewBrowserClient.h#L367

https://github.com/winsoft666/QCefWidget/blob/3237d0165b51c60f8deb5e2919420d0a33ce50a1/src/QCefWidget/CefBrowserApp/QCefBrowserHandler.h#L256

liaowubinf commented 2 weeks ago

先确认一下,你是使用的哪个仓库? https://github.com/CefView/CefViewCore/blob/fe335787e8ce5d9bf719617a248c5a9bf7e8e35c/include/CefViewBrowserClient.h#L367

https://github.com/winsoft666/QCefWidget/blob/3237d0165b51c60f8deb5e2919420d0a33ce50a1/src/QCefWidget/CefBrowserApp/QCefBrowserHandler.h#L256

仓库没错, 头文件就是跟这个仓库一样的,里面的用法也是QCefview, 但是之前有onBeforeBrowse, 升级dll后编译报错了

L-Super commented 2 weeks ago

想问下没有这个onBeforeBrowse方法, 还有别的方式能拦截window.location.href这种redirect吗

可以参考文档,看哪个函数能够实现您的目的。感觉可以通过addressChanged进行判断。

tishion commented 2 weeks ago

QCefView没有暴露过这个接口给上层,需要的话你自己实现就行了。

liaowubinf commented 2 weeks ago

想问下没有这个onBeforeBrowse方法, 还有别的方式能拦截window.location.href这种redirect吗

可以参考文档,看哪个函数能够实现您的目的。感觉可以通过addressChanged进行判断。

不行, adressChanged是 ed ,代表是改变之后的, 不能阻断redirect