在create-web-view中,新窗口的uri在哪里? [英] Where is the uri of the new window, in create-web-view?

查看:89
本文介绍了在create-web-view中,新窗口的uri在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档 ,当Webkit创建新窗口时,将调用create-new-window信号.我一直试图覆盖它以处理PyGTK Webkit浏览器中的<a target='_blank'链接.在WebView的子类中,我有:

According to the documentation, the create-new-window signal is called when a webkit is creating a new window. I've been trying to override this to handle <a target='_blank' links in PyGTK webkit browser. In a subclass of WebView I have:

...

self.connect("create-web-view", self.newWin)

...

def newWin(view, frame, data):
    print view.get_property('uri')
    print frame.get_property('uri')
    print data.get_property('uri')

当单击一个新窗口链接时会调用它,但是由于某些原因所有这些对象都显示相同的URL,终端会打印出 current 页面URL三次.如何找到应该传递给新窗口的网址?

It is called when a new-window link is clicked, but for some reason all of these objects show the same url, the terminal prints out the current page url three times. How can I find the url that is supposed to be passed to a new window?

多亏了番茄,我找到了解决方案.将信号设置为此功能有效:

Thanks to ptomato, I found a solution. Setting the signal to this function works:

...
self.connect("new-window-policy-decision-requested", self.newWin) #requires webkit 1.1.4

...

def newWin(self, view, frame, request, nav_action, policy_decision):
    """
    Calls the default browser on external link requests.
    """
    functiontoviewurl(request.get_uri())
    # According to the documentation: http://webkitgtk.org/reference/webkitgtk/stable/webkitgtk-webkitwebview.html#WebKitWebView-new-window-policy-decision-requested
    # call ignore on the policy decision, then return true (that is, we handled it).
    policy_decision.ignore()
    return True

推荐答案

您无法通过捕获该信号来拦截新窗口的创建-到那时,浏览器已经决定要创建一个新窗口.而是连接到 new-window-policy-decision-requested 并从request参数获取URI.

You can't intercept the creation of a new window by catching that signal - by that time, the browser has already decided it will create a new window. Instead, connect to new-window-policy-decision-requested and get the URI from the request parameter.

这篇关于在create-web-view中,新窗口的uri在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆