Nava Carmon
Nava Carmon

Reputation: 4533

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 catch 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

Upvotes: 2

Views: 2716

Answers (1)

LaC
LaC

Reputation: 12824

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).

Upvotes: 1

Related Questions