开发者

Open link in default browser with window.open and set window size from webView in cocoa

I have a button in my webView, which does the following:

myButton.onClick = function(){
   window.open("http://myURL.com",'about:blank','Popup_Window','width:200,height:200');
}

Basically it just tries to open another window. I catc开发者_如何学JAVAh this click in my delegate function: like this:

- (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
    [[NSWorkspace sharedWorkspace] openURL:[actionInformation objectForKey:WebActionOriginalURLKey]];
}

and open this link in default browser's new window. The problem is that the width, height properties of this function are get lost. How do I open a default browser with this predefined size?

Thanks in advance


You don't. You can try using AppleScript to tell the browser to make a new window of the desired size, and then to show that url in it (but the exact method will depend on the browser), or you can have the webpage attempt to resize the window after the fact (but this is going to anger users if their browser is set to open external links in a new tab instead of a new window).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜