Cocoa / WebKit,具有“window.open()”在Safari实例中打开的JavaScript链接 [英] Cocoa/WebKit, having "window.open()" JavaScript links opening in an instance of Safari

查看:508
本文介绍了Cocoa / WebKit,具有“window.open()”在Safari实例中打开的JavaScript链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WebKit构建一个真正基本的Cocoa应用程序,在其中显示一个Flash / Silverlight应用程序。非常基本,没有意图成为一个浏览器本身。

I am building a really basic Cocoa application using WebKit, to display a Flash/Silverlight application within it. Very basic, no intentions for it to be a browser itself.

到目前为止我已经能够得到它打开基本的html链接( ; a href =.../> )在新的Safari实例中使用

So far I have been able to get it to open basic html links (<a href="..." />) in a new instance of Safari using

[[NSWorkspace sharedWorkspace] openURL:[request URL]];

现在我的困难是在窗口中打开Safari新实例中的链接.open()用于JavaScript。我认为(和这一点,我一直在黑客的代码,不确定如果我实际上是否)我有这种工作通过设置WebView的 policyDelegate 并执行

Now my difficulty is opening a link in a new instance of Safari when window.open() is used in JavaScript. I "think" (and by this, I have been hacking away at the code and am unsure if i actually did or not) I got this kind of working by setting the WebView's policyDelegate and implementing its

-webView:decidePolicyForNavigationAction:request:frame:decisionListener:

委托方法。但是这导致一些不稳定的行为。

delegate method. However this led to some erratic behavior.

所以这么简单的问题,我需要做什么,当 window.open code>

So the simple question, what do I need to do so that when window.open() is called, the link is opened in a new instance of Safari.

感谢

大点,我通常是.NET开发人员,并且只使用Cocoa / WebKit几天。

Big point, I am normally a .NET developer, and have only been working with Cocoa/WebKit for a few days.

推荐答案

我已经在使用 webView:decisionPolicyForNewWindowAction:request:newFrameName:decisionListener:并且我已经使用锚标签,但是该方法似乎不会在调用JavaScript时被调用。

I am already using webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener: and I have gotten it to work with anchor tags, however the method never seems to get called when JavaScript is invoked.

但是当 window.open()被调用 webView:createWebViewWithRequest:request 被调用,我试图强制窗口在Safari中打开这里,但请求始终为null。所以我永远不能读取网址。

However when window.open() is called webView:createWebViewWithRequest:request is called, I have tried to force the window to open in Safari here, however request is always null. So I can never read the URL out.

我已经做了一些搜索,这似乎是一个已知的 misfeature ,但我没能找到办法解决它。

I have done some searching around, and this seems to be a known "misfeature" however I have not been able to find a way to work around it.

根据我的理解 createWebViewWithRequest 可以创建新的webview,然后发送请求的url到新的webView加载。 这是我能够做到的最好的解释找到到目前为止。

From what I understand createWebViewWithRequest gives you the ability to create the new webview, the the requested url is then sent to the new webView to be loaded. This is the best explanation I have been able to find so far.

因此,虽然很多人都指出了这个问题,我还没有看到任何适合我的需要的解决方案。我将再次尝试深入探讨 decisionPolicyForNewWindowAction

So while many people have pointed out this problem, I have yet to see any solution which fits my needs. I will try to delve a little deeper into the decidePolicyForNewWindowAction again.

谢谢!

这篇关于Cocoa / WebKit,具有“window.open()”在Safari实例中打开的JavaScript链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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