C# Render HTML to get element's height

孤街醉人 提交于 2019-12-13 15:26:24

问题


I need to create an HTML page from a C# code with HTML Agility Pack. What I want is that if the element I'm trying to write cannot fit into a div with a specific height, it must create a new div and close the other one (like a paging if you want). My big concern is how to know the height of my element inside C#, I assume I'm force to render it somewhere with the CSS associated, but how?


回答1:


One way to do this is using an HTML renderer like WebKit.NET.

You would then be able to call the javascript in it to retrieve DOM objects properties like heights, position, etc...

Once you have set and rendered the content you want to test (tutorial here), use StringByEvaluatingJavaScriptFromString function to access javascript functions.

string height = webKitBrowser1.StringByEvaluatingJavaScriptFromString("$('#divID').height().toString()");

Note that you need to return a string value as this function does not return other types.



来源:https://stackoverflow.com/questions/18613721/c-sharp-render-html-to-get-elements-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!