Where is the uri of the new window, in create-web-view?

非 Y 不嫁゛ 提交于 2019-12-11 09:17:56

问题


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')

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

回答1:


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.



来源:https://stackoverflow.com/questions/12127970/where-is-the-uri-of-the-new-window-in-create-web-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!