可可:webView有超链接,添加`target = _blank“`无法打开 [英] cocoa:webView which have hyperlinks to add the ` target = " _blank "` can not be opened
问题描述
webView其中有超链接以添加 target =_blank
无法打开。
webView which have hyperlinks to add the target = " _blank "
can not be opened.
一个webview样应用程序,但我有一个问题。如何在当前应用程序的新窗口中打开链接 - 而不是在safari?
I developing a webview-like application, but i have one problem. How to open link in new window in current application - not in safari?
感谢您的帮助。
img src =https://i.stack.imgur.com/RK6vc.pngalt =enter image description here>
@Rob Keniger代码是不需要运行
@Rob Keniger The code is not running.why?
推荐答案
您需要将一个对象设置为 UIDelegate
您的 WebView
,并在该对象中实现 webView:createWebViewWithRequest:
方法。
You need to set an object as the UIDelegate
of your WebView
and in that object implement the webView:createWebViewWithRequest:
method.
在执行该方法时,您需要打开一个包含单独 WebView
的新窗口, mainFrame
加载作为参数传递给方法的 URLRequest
。
In your implementation of that method, you need to open a new window containing a separate WebView
and then tell its mainFrame
to load the URLRequest
passed as a parameter to the method.
更新:
我查看了您的代码。您需要将一个对象指定为Web视图的 UIDelegate
,因此将 [webView setUIDelegate:self]
code> applicationDidFinishLaunching:。
I've looked at your code. You need to assign an object as the web view's UIDelegate
, so add a [webView setUIDelegate:self]
line into applicationDidFinishLaunching:
.
如何实现委托的一个非常简单的例子是:
A very simple example of how to implement the delegate would be:
- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request
{
NSUInteger windowStyleMask = NSClosableWindowMask |
NSMiniaturizableWindowMask |
NSResizableWindowMask |
NSTitledWindowMask;
NSWindow* webWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600) styleMask:windowStyleMask backing:NSBackingStoreBuffered defer:NO];
WebView* newWebView = [[WebView alloc] initWithFrame:[webWindow contentRectForFrameRect:webWindow.frame]];
[newWebView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[webWindow setContentView:newWebView];
[webWindow center];
[webWindow makeKeyAndOrderFront:self];
[[newWebView mainFrame] loadRequest:request];
return newWebView;
}
这篇关于可可:webView有超链接,添加`target = _blank“`无法打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!