【问题标题】:Where is the uri of the new window, in create-web-view?在 create-web-view 中,新窗口的 uri 在哪里?
【发布时间】:2012-08-26 06:04:31
【问题描述】:

根据the documentation,当 webkit 创建新窗口时会调用 create-new-window 信号。我一直在尝试覆盖它来处理 PyGTK webkit 浏览器中的 <a target='_blank' 链接。在 WebView 的子类中,我有:

...

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,终端打印出 当前页面 url 三次。如何找到应该传递到新窗口的 url?

感谢 ptomato,我找到了解决方案。将信号设置为此功能有效:

...
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

【问题讨论】:

    标签: html webkit gtk signals pygtk


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-17
      • 2011-08-03
      • 2018-03-17
      • 1970-01-01
      相关资源
      最近更新 更多