objective-c - WebView加载html时,不能响应模态窗口
天蓬老师
天蓬老师 2017-05-02 09:23:47
0
2
718

RT,在OSX下的WebView中(非iOS),加载html网页时,window.showModalDialog这句js无效,无法弹窗,在Safari中加载同样网页时有响应,请问有大神做过类似的问题么?
代码如下:

- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request{
    
    NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 300) styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask backing:NSBackingStoreBuffered defer:YES];
    [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
    WebView *webView = [[WebView alloc] init];
    [webView setFrameLoadDelegate:self];
    window.contentView = webView;
    [webView.mainFrame loadRequest:request];
    [window makeKeyAndOrderFront:self];
    return webView;
    
}

- (WebView *)webView:(WebView *)sender createWebViewModalDialogWithRequest:(NSURLRequest *)request{
 
   return [self webView:sender createWebViewWithRequest:request];

}

- (void)webViewRunModal:(WebView *)sender{

   [sender.window makeKeyAndOrderFront:self];
    
}

- (void)webViewShow:(WebView *)sender{
    
    [sender.window makeKeyAndOrderFront:self];
    
}

- (void)webViewClose:(WebView *)sender{

    [sender.window close];
    
}
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

Antworte allen(2)
给我你的怀抱

最好不要用showModalDialog,换成p比较好,osx的webview我没用过,但是以前做android开发的时候,webview是不支持模态窗口的弹出的,换成p才行,不知道osx的webview不弹出是不是这个原因

黄舟

调试了很久终于解决了,提供一下代码给后来人一个思路。

     #pragma -mark -WebView Delegate
    
        - (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request{
     NSUInteger windowStyleMask = NSClosableWindowMask|NSMiniaturizableWindowMask|NSTitledWindowMask;
     _webWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 300) styleMask:windowStyleMask backing:NSBackingStoreNonretained defer:YES];
     [_webWindow setReleasedWhenClosed:NO];
     WebView* newWebView = [[WebView alloc] initWithFrame:[_webWindow  contentRectForFrameRect:_webWindow.frame]];
    [newWebView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
    [[newWebView mainFrame] loadRequest:request];
    [_webWindow setContentView:newWebView];
    [_webWindow center];
    [_webWindow makeKeyAndOrderFront:nil];
 
    return newWebView;
 
     }


      - (WebView *)webView:(WebView *)sender createWebViewModalDialogWithRequest:(NSURLRequest *)request{
 
    return [self webView:sender createWebViewWithRequest:request];
     }


    - (void)webViewRunModal:(WebView *)sender{
 
    [sender.window makeKeyAndOrderFront:self];
 
    }

    - (void)webViewShow:(WebView *)sender{
  
    [sender.window makeKeyAndOrderFront:self];
 
    }

    - (void)webViewClose:(WebView *)sender{
    [sender.window close];
    }

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage