2
有超链接添加target = " _blank "
的webView无法打开。可可:webView有超链接添加`target =“_blank”`无法打开
我开发了一个类似webview的应用程序,但我有一个问题。如何在当前应用程序的新窗口中打开链接 - 不在safari中?
感谢您的帮助。
@Rob Keniger代码不是running.why?
有超链接添加target = " _blank "
的webView无法打开。可可:webView有超链接添加`target =“_blank”`无法打开
我开发了一个类似webview的应用程序,但我有一个问题。如何在当前应用程序的新窗口中打开链接 - 不在safari中?
感谢您的帮助。
@Rob Keniger代码不是running.why?
您需要将对象设置为WebView
的UIDelegate
,并在该对象中实施webView:createWebViewWithRequest:
方法。
在您实现该方法时,需要打开一个包含单独的WebView
的新窗口,然后告知其mainFrame
加载URLRequest
作为参数传递给该方法。
更新:
我看过你的代码。您需要将对象指定为网络视图的UIDelegate
,因此请将[webView setUIDelegate:self]
行添加到applicationDidFinishLaunching:
。
如何实现委托将是一个非常简单的例子:
- (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;
}
你给我一个样品? – 2012-04-25 15:08:22
你给我一个样本?我试过了,没有效果。 – 2012-04-25 15:21:45
'[self stringByEvaluatingJavaScriptFromString:js];'在页面上使用javascript,删除''_blank'''。这种方法不好。 – 2012-04-25 15:26:58