Re: Optimal height for WebView
I think I've finally got a good answer for how to compute the height of the content of a WebView. The trick seems to be to give an element an ID (in this case 'foo' ) and then evaluate: @document.getElementById(\foo\).scrollHeight; on that element. This does appear to give the correct height of the content. However, for some reason, after I set the frame on the WebView inside of my split view, the split view decides to change the height. I've got a test project at: http://ericgorr.net/cocoadev/webviewtest2.zip If anyone wanted to take a look...unless you know already what has gone wrong. Thank you. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Optimal height for WebView
Sent from my iPhone On Jan 4, 2013, at 9:45 PM, Steve Christensen puns...@mac.com wrote: On Jan 4, 2013, at 10:40 AM, Mike Abdullah wrote: On 4 Jan 2013, at 18:12, Eric Gorr mail...@ericgorr.net wrote: Good point Mike. However, after it has completed the layout, is it possible to determine the height of the content? If so, i could probably work with that information. But, I would still think it was possible to provide a method with a fixed width, have it perform a layout, and return the height - that is essentially what the stackoverflow solution does, just in a rather convoluted way. Well you've got the whole DOM API to play with. I'd have a play around with computed style etc. to see if you can pull out a useful figure. Ask the DOM what the height is. I use jquery but you could just as easily use standard Javascript methods to get the height. - (void) webViewDidFinishLoad:(UIWebView*)webView { height = [[webView stringByEvaluatingJavaScriptFromString:@$(document).height();] integerValue]; } At least for me, this returns a value of zero. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Optimal height for WebView
On 14 Jan 2013, at 18:09, Eric Gorr mail...@ericgorr.net wrote: Sent from my iPhone On Jan 4, 2013, at 9:45 PM, Steve Christensen puns...@mac.com wrote: On Jan 4, 2013, at 10:40 AM, Mike Abdullah wrote: On 4 Jan 2013, at 18:12, Eric Gorr mail...@ericgorr.net wrote: Good point Mike. However, after it has completed the layout, is it possible to determine the height of the content? If so, i could probably work with that information. But, I would still think it was possible to provide a method with a fixed width, have it perform a layout, and return the height - that is essentially what the stackoverflow solution does, just in a rather convoluted way. Well you've got the whole DOM API to play with. I'd have a play around with computed style etc. to see if you can pull out a useful figure. Ask the DOM what the height is. I use jquery but you could just as easily use standard Javascript methods to get the height. - (void) webViewDidFinishLoad:(UIWebView*)webView { height = [[webView stringByEvaluatingJavaScriptFromString:@$(document).height();] integerValue]; } At least for me, this returns a value of zero. Steve showed an example of how you could do this using jquery. Thus, the above script will work *only* if the web page has jquery loaded into it. You likely want to figure out how to do it without jquery. Ultimately here, web pages are complex beasts. You're going to have to understand a least a little of the DOM and how it works in order to figure out the optimum height for a given page. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Optimal height for WebView
It seems like this should be a simple question. I can access the NSScrollView of the WebView and ask the scroll view for the height of its document view, but the height it returns is the current height of the WebView, not the height of the content it currently contains. If I reduce the height of the WebView, eventually the vertical scrollbar will appear, so someone knows the real height of the content the WebView contains. I simple want to be able to obtain that value so I can size the WebView to this height, if it is reasonable to do so. How can I do this? Various proposed solutions I have found do not work. Thank you. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Optimal height for WebView
On Jan 4, 2013, at 9:19 AM, Eric Gorr wrote: It seems like this should be a simple question. I can access the NSScrollView of the WebView and ask the scroll view for the height of its document view, but the height it returns is the current height of the WebView, not the height of the content it currently contains. If I reduce the height of the WebView, eventually the vertical scrollbar will appear, so someone knows the real height of the content the WebView contains. I simple want to be able to obtain that value so I can size the WebView to this height, if it is reasonable to do so. How can I do this? Various proposed solutions I have found do not work. First off, to avoid someone proposing a solution that you have already tried, you should actually mention which proposed solutions you have tried and how they didn't work for your case. So, risking that you have already tried this, what does [[yourWebView mainFrame] webView] frame] give you? HTH, Keary Suska Esoteritech, Inc. Demystifying technology for your home or business ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Optimal height for WebView
Sent from my iPhone On Jan 4, 2013, at 11:34 AM, Keary Suska cocoa-...@esoteritech.com wrote: On Jan 4, 2013, at 9:19 AM, Eric Gorr wrote: It seems like this should be a simple question. I can access the NSScrollView of the WebView and ask the scroll view for the height of its document view, but the height it returns is the current height of the WebView, not the height of the content it currently contains. If I reduce the height of the WebView, eventually the vertical scrollbar will appear, so someone knows the real height of the content the WebView contains. I simple want to be able to obtain that value so I can size the WebView to this height, if it is reasonable to do so. How can I do this? Various proposed solutions I have found do not work. First off, to avoid someone proposing a solution that you have already tried, you should actually mention which proposed solutions you have tried and how they didn't work for your case. So, risking that you have already tried this, what does [[yourWebView mainFrame] webView] frame] give you? The current height of the WebView, not the height of the content - which is smaller. I did just locate a solution that does work, but I am not really happy with it because it seems more complicated then it should be. Check out: http://stackoverflow.com/questions/2675244/how-to-resize-webview-according-to-its-content Note, it does not appear to be necessary to disable the scrolling and it is necessary to first resize the WebView to a small height as mentioned by Miraaj in a comment on the answer. Now, one problem i am having with this solution is that I see a flicker with the WebView shrinking and then growing larger. It really does seem like there should be a way to ask for the height of the content regardless of the current height of the WebView. If there is not, I will probably go ahead and file a bug. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Optimal height for WebView
On 4 Jan 2013, at 17:19, Eric Gorr mail...@ericgorr.net wrote: Sent from my iPhone On Jan 4, 2013, at 11:34 AM, Keary Suska cocoa-...@esoteritech.com wrote: On Jan 4, 2013, at 9:19 AM, Eric Gorr wrote: It seems like this should be a simple question. I can access the NSScrollView of the WebView and ask the scroll view for the height of its document view, but the height it returns is the current height of the WebView, not the height of the content it currently contains. If I reduce the height of the WebView, eventually the vertical scrollbar will appear, so someone knows the real height of the content the WebView contains. I simple want to be able to obtain that value so I can size the WebView to this height, if it is reasonable to do so. How can I do this? Various proposed solutions I have found do not work. First off, to avoid someone proposing a solution that you have already tried, you should actually mention which proposed solutions you have tried and how they didn't work for your case. So, risking that you have already tried this, what does [[yourWebView mainFrame] webView] frame] give you? The current height of the WebView, not the height of the content - which is smaller. I did just locate a solution that does work, but I am not really happy with it because it seems more complicated then it should be. Check out: http://stackoverflow.com/questions/2675244/how-to-resize-webview-according-to-its-content Note, it does not appear to be necessary to disable the scrolling and it is necessary to first resize the WebView to a small height as mentioned by Miraaj in a comment on the answer. Now, one problem i am having with this solution is that I see a flicker with the WebView shrinking and then growing larger. It really does seem like there should be a way to ask for the height of the content regardless of the current height of the WebView. If there is not, I will probably go ahead and file a bug. The problem you're up against here is that it's possible for web content to lay itself out based on the browser's size. As soon as you run into a webpage that does that, there's no to know the optimal size, short of trying them all. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Optimal height for WebView
Good point Mike. However, after it has completed the layout, is it possible to determine the height of the content? If so, i could probably work with that information. But, I would still think it was possible to provide a method with a fixed width, have it perform a layout, and return the height - that is essentially what the stackoverflow solution does, just in a rather convoluted way. On Jan 4, 2013, at 12:22 PM, Mike Abdullah cocoa...@mikeabdullah.net wrote: On 4 Jan 2013, at 17:19, Eric Gorr mail...@ericgorr.net wrote: Sent from my iPhone On Jan 4, 2013, at 11:34 AM, Keary Suska cocoa-...@esoteritech.com wrote: On Jan 4, 2013, at 9:19 AM, Eric Gorr wrote: It seems like this should be a simple question. I can access the NSScrollView of the WebView and ask the scroll view for the height of its document view, but the height it returns is the current height of the WebView, not the height of the content it currently contains. If I reduce the height of the WebView, eventually the vertical scrollbar will appear, so someone knows the real height of the content the WebView contains. I simple want to be able to obtain that value so I can size the WebView to this height, if it is reasonable to do so. How can I do this? Various proposed solutions I have found do not work. First off, to avoid someone proposing a solution that you have already tried, you should actually mention which proposed solutions you have tried and how they didn't work for your case. So, risking that you have already tried this, what does [[yourWebView mainFrame] webView] frame] give you? The current height of the WebView, not the height of the content - which is smaller. I did just locate a solution that does work, but I am not really happy with it because it seems more complicated then it should be. Check out: http://stackoverflow.com/questions/2675244/how-to-resize-webview-according-to-its-content Note, it does not appear to be necessary to disable the scrolling and it is necessary to first resize the WebView to a small height as mentioned by Miraaj in a comment on the answer. Now, one problem i am having with this solution is that I see a flicker with the WebView shrinking and then growing larger. It really does seem like there should be a way to ask for the height of the content regardless of the current height of the WebView. If there is not, I will probably go ahead and file a bug. The problem you're up against here is that it's possible for web content to lay itself out based on the browser's size. As soon as you run into a webpage that does that, there's no to know the optimal size, short of trying them all. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Optimal height for WebView
On 4 Jan 2013, at 18:12, Eric Gorr mail...@ericgorr.net wrote: Good point Mike. However, after it has completed the layout, is it possible to determine the height of the content? If so, i could probably work with that information. But, I would still think it was possible to provide a method with a fixed width, have it perform a layout, and return the height - that is essentially what the stackoverflow solution does, just in a rather convoluted way. Well you've got the whole DOM API to play with. I'd have a play around with computed style etc. to see if you can pull out a useful figure. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Optimal height for WebView
On Jan 4, 2013, at 10:40 AM, Mike Abdullah wrote: On 4 Jan 2013, at 18:12, Eric Gorr mail...@ericgorr.net wrote: Good point Mike. However, after it has completed the layout, is it possible to determine the height of the content? If so, i could probably work with that information. But, I would still think it was possible to provide a method with a fixed width, have it perform a layout, and return the height - that is essentially what the stackoverflow solution does, just in a rather convoluted way. Well you've got the whole DOM API to play with. I'd have a play around with computed style etc. to see if you can pull out a useful figure. Ask the DOM what the height is. I use jquery but you could just as easily use standard Javascript methods to get the height. - (void) webViewDidFinishLoad:(UIWebView*)webView { height = [[webView stringByEvaluatingJavaScriptFromString:@$(document).height();] integerValue]; } ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com