xcode osx webview新窗口

xcode osx webview新窗口,webview,webbrowser-control,Webview,Webbrowser Control,我对webview有问题 我为Osx制作了一个简单的webbrowser,在其中我必须隐藏搜索栏、菜单和右键单击,用户只能进入一个特定的url 所有这些都没问题,但我需要允许空白目标。。我是说。。我有一些目标为空的链接,所以要在新窗口中打开,但它不起作用,我不知道热允许这样做 这是我的DataOAppDelegate.h代码: #import <Cocoa/Cocoa.h> #import <WebKit/WebKit.h> @interface DataOAp

我对webview有问题

我为Osx制作了一个简单的webbrowser,在其中我必须隐藏搜索栏、菜单和右键单击,用户只能进入一个特定的url

所有这些都没问题,但我需要允许空白目标。。我是说。。我有一些目标为空的链接,所以要在新窗口中打开,但它不起作用,我不知道热允许这样做

这是我的DataOAppDelegate.h代码:

    #import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>

@interface DataOAppDelegate : NSObject <NSApplicationDelegate,NSWindowDelegate>
{WebView *WebView;

    //other instance variable
}

@property (assign) IBOutlet NSWindow *window;

@property (retain, nonatomic) IBOutlet WebView *myWebView;



@end
#导入
#进口
@接口DataOAppDelegate:NSObject
{WebView*WebView;
//其他实例变量
}
@属性(分配)窗口*窗口;
@属性(保留,非原子)IBOutlet WebView*myWebView;
@结束
和DataOAppDelegate.m的代码

#import "DataOAppDelegate.h"
//#import <WebKit/WebKit.h>


@implementation DataOAppDelegate
@synthesize window;
@synthesize myWebView;

//your function etc



-(void)awakeFromNib{

    NSString *urlText = @"http://website.com";
    [[myWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
    [myWebView setDrawsBackground:NO];
    [window setDelegate:self];
}


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{

    [myWebView setUIDelegate:self];
    NSString *urlText = @"http://website.com";
    [[myWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
}


- (WebView *)myWebView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request
{
    NSLog(@"sss%@",sender);
    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;
}

- (void)launchSoftWithBundleID:(NSString *)softPath
{
    NSBundle *softBundle = [NSBundle bundleWithPath:softPath];
    NSString *bundleID = [softBundle bundleIdentifier];
    //
    NSTask *softTask = [[NSTask alloc] init];
    [softTask setLaunchPath:softPath];
    [softTask launch];
    //
    NSArray *array = [NSRunningApplication runningApplicationsWithBundleIdentifier:bundleID];
    if ([array count] > 0)
    {
        NSRunningApplication *runningApp = [array objectAtIndex:0];
        [runningApp activateWithOptions:NSApplicationActivateIgnoringOtherApps];
    }
}
#导入“DataOAppDelegate.h”
//#进口
@实现DataOAppDelegate
@合成窗口;
@综合myWebView;
//你的职能等
-(无效)从NIB中唤醒{
NSString*urlText=@”http://website.com";
[[myWebView大型机]加载请求:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]];
[myWebView setDrawsBackground:否];
[窗口设置代理:self];
}
-(无效)ApplicationIDFinishLaunching:(NSNotification*)通知
{
[myWebView setUIDelegate:self];
NSString*urlText=@”http://website.com";
[[myWebView大型机]加载请求:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]];
}
-(WebView*)myWebView:(WebView*)发件人创建WebViewWithRequest:(NSURLRRequest*)请求
{
NSLog(@“sss%@”,发送方);
NSU整型windowStyleMask=NSClosableWindowMask|
小型化窗口掩模|
nsresizeblewindowmask|
NSTitledWindowMask;
NSWindow*webWindow=[[NSWindow alloc]initWithContentRect:NSMakeRect(0,0,800,600)样式掩码:windowStyleMask backing:NSBackingStoreBuffered defer:NO];
WebView*newWebView=[[WebView alloc]initWithFrame:[webWindow contentRectForFrameRect:webWindow.frame]];
[newWebView设置自动重新设置任务:NSViewWidthSizable | NSViewHeightSizable];
[webWindow setContentView:newWebView];
[网络窗口中心];
[webWindow MakeKeyandDerfront:self];
[[newWebView大型机]加载请求:请求];
返回newWebView;
}
-(void)使用BundleId:(NSString*)软路径启动软件
{
NSBundle*softBundle=[NSBundle bundleWithPath:softPath];
NSString*bundleID=[SoftBundleId];
//
NSTask*softTask=[[NSTask alloc]init];
[softTask setLaunchPath:softPath];
[软任务启动];
//
NSArray*数组=[NSRunningApplication runningApplicationsWithBundleIdentifier:bundleID];
如果([数组计数]>0)
{
NSRunningApplication*runningApp=[array objectAtIndex:0];
[运行应用程序激活选项:非应用程序激活信号或其他应用程序];
}
}

Web视图有委托方法来执行此操作:
decidePolicyForNavigationAction
decidePolicyForNewWindowAction
()

-(void)webView:(webView*)发送方决策fornavigationAction:(NSDictionary*)操作信息请求:(NSURLRequest*)请求帧:(WebFrame*)帧决策侦听器:(id)侦听器{
如果([发送者相等:self.yourveview]){
[听众使用];
}
否则{
[[NSWorkspace sharedWorkspace]openURL:[actionInformation objectForKey:WebActionOriginalURLKey]];
[听者忽略];
}
}
-(void)webView:(webView*)发送方决策策略fornewwIndowAction:(NSDictionary*)操作信息请求:(NSURLRequest*)请求新框架名:(NSString*)框架名决策侦听器:(id)侦听器{
[[NSWorkspace sharedWorkspace]openURL:[actionInformation objectForKey:WebActionOriginalURLKey]];
[听者忽略];
}
注意:不要忘记为您的WebView设置策略委托

- (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener {
    if ([sender isEqual:self.YourVebView]) {
        [listener use];
    }
    else {
        [[NSWorkspace sharedWorkspace] openURL:[actionInformation objectForKey:WebActionOriginalURLKey]];
        [listener ignore];
    }
}

- (void)webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id<WebPolicyDecisionListener>)listener {
    [[NSWorkspace sharedWorkspace] openURL:[actionInformation objectForKey:WebActionOriginalURLKey]];
    [listener ignore];
}