I'm having trouble resizing a WebView element to fit its content. I don't want to resize the content, I want the WebView and its containing Custom View and NSWindow to resize to fit the content.
At the moment i've tried using JavaScript to get the width and height and resizing the 3 elements, as well as using NSRect and setFrameSize but with no luck (shown below).
So basically, if I have an NSWindow with a Custom View with a Web View, how do I get them to resize to fit the content of the WebView?
Thanks in advance everyone!
This is what I have at the moment which just makes a big mess (it doesn't resize the main window, and makes the contents of the window spill out of it).
NSString *width = [_myWebView stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth;"];
NSString *height = [_myWebView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
NSSize size;
size.width = [width floatValue];
size.height = [height floatValue];
NSRect mySize = NSMakeRect(_window.frame.origin.x, _window.frame.origin.y, size.width, size.height);
[_window setFrame:mySize display:YES]; // Resize main NSWindow
[_webViewView setFrameSize:size]; // Resize custom view of main NSWindow
[_myWebView setFrameSize:size]; // Resize WebView in custom view