I am working on a Web application that uses the Windows Forms C# Webbrowser to take screenshots of Web pages and save them for archiving purposes.
I am running into an issue with pages that use max-device-width in CSS media queries for responsive layout.
Apparently the max-device-width for the Webbrowser control defaults to 1024 px which causes certain CSS rules to fire resulting in layout issues.
Using max-width in the media queries would probably fix this, but would have the undesired effects when resizing the browser window on desktop browsers.
Is there some way of specifying the max-device-width of the Webbrowser?
Related
I have a web browser control hosted on a WPF window so I can display html/css pages. I am having issues with my web browser control using Internet Explorer's zoom factor. The web browser control takes internet explorers zoom level to distort and mess up the way my HTML looks.
For example, if I set Internet Explorer to zoom at 150%, and the web browser will start zoomed in 150%.
I've tried using the zoom CSS property and the HTML document.style.zoom but the browser ignores my changes and takes IE's zoom. Is there a way to ignore Internet Explorer options through either my C# or overwrite them in my HTML/CSS?
Well, after searching through the internet I didn't find too many viable solutions.
I did think of a temporary workaround however. The IE zoomfactor is controlled in the registry key. Setting the registry key there controls what the web browser control sets its zoom to.
var key = "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Internet Explorer\\Zoom\\";
Registry.SetValue(key, "ZoomFactor", 0x186a0, RegistryValueKind.DWord); //0x1860a is 100%
I am developing responsive web application in the asp.net mvc.
I want to set some product boxes based on the Current browser/screen resolution, but i am getting issue in getting the correct width of browser resolution.
If I write Request.Browser.ScreenPixelsWidth it gives me all time 640*480.
But its wrong. And if I write the var screen = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
var width = screen.Width;
Its giving me correct windows resolution which i have set from my window property. Its giving me 1600*900 which is correct value. But issue here is if i manually make my browser screen small and run again that code at that it also gives me 1600*900, but it should give me the size of what i have done manually small.
Any idea?
Handling browser size on the server, you won't know if the user resizes the browser between requests. The correct way to handle browser size is on the client with CSS media queries. Media queries allow you to dynamically set different styles for different browser sizes, i.e. a more responsive layout. Here's a decent intro:
http://kyleschaeffer.com/development/responsive-layouts-using-css-media-queries/
How do I add IFrame in a Silverlight 4.0 User control ?
And I want a button on the control that refreshes the IFrame. Is that possible?
To render HTML on top of silverlight, you have to use WindowLess mode. This is a configuration in the object tag. Then you'll need to manually program your IFrame to float in the correct location using javascript or the bridge provided by Silverlight. You can use a commercial control like Robaticus suggested or figure it out on your own.
Either way, none of these options work for Mac. So if you're developing for Windows only, then you're ok. Anyone using Mac will not see any HTML float on top of Silverlight.
If you absolutely want an IFrame in the HTML page (contrary to what the other answers suggest) you could obtain access to the IFrame in Silverlight by using the HTML Bridge
I think you can use WebBrowser class to display IFrame content in Silverlight. Or check this link it will also help you. - How to use iFrame tag in XAML Silverlight 4?
The iframe tag is HTML, not Silverlight. If you have an out-of-browser Silverlight application, you could potentially use the WebBrowser control, but this is not available for in-browser applications.
There is an approach out there where you can essentially make a DIV on your hosting page appear overtop of your Silverlight application, but, in my experience, this is very hard to control, and the visual results are less-than-ideal.
Additionally, there are a few commercial components that do HTML rendering, but they all seem to use the same approach of a floating DIV, and they are not as reliable as I would like to see them.
I am building a windows forms application that I will be adding a control within that will display quite a bit of different data. For the most part the data inside will be navigation buttons and help/training text.
I think it would be ideal if I could write the contents in HTML and then just display that in the control in the application, but I am not sure if this is a good idea.
Another point to note is there will be a web based version of the same application at some point in the near future, and doing this part of the application in HTML will make for very easy reusability.
The users will not have IIS installed, if this matters.
For this purpose, I think that an embedded web browser would be absolutely great. Alot of applications use a web browser control for navigation, information, training, etc. Steam is one example. In addition, reusability is almost always a best practice.
But I would use WebKit instead of the built-in IE web browser control.
I have a similar application and I think the WebBrowser control works very well. If you think it's what you need, I would for it and there's many other applications that do something similar. You can call Javascript functions in the HTML page from C# using HtmlDocument.InvokeScript(), and C# from Javascript using window.external and having this two-way communication makes life simple.
Users do not need IIS installed as you're not running a web server, just displaying content using HTML.
I would go for the built-in IE control rather than webkitdotnet to be honest. Although WebKit itself is superior to IE, the webkitdotnet project at version 0.5 it doesn't have the C#<> JavaScript communication or DOM access and it seems hard to tell if it's still being actively developed. It'll be great if/when it gets feature parity as IE is obviously far from perfect, but the advantage of the built-in IE control is every user of your app will have it already installed and the WebBrowser control is well tested. There are some disadvantages I've found:
IE versions may range from 6 to 9, so you'll to test to make sure your content works in all (as with a website).
There's a bug in IE (at least up to 8) that relative links do not work in combination with a <base href="file://...">. This can stop you being able to use relative links in your local HTML documents.
Sometimes pages display differently inside the WebBrowser control than they do out of it. For instance, http://bugs.jquery.com/ticket/7104 is one and I've come across another similar bug affecting cufon.
For compatibility reasons, even if your users install IE > 7 the WebBrowser control will still render your content in IE7 rendering mode by default. This is different to standalone IE which renders in the most-standard mode by default, so it can catch you out if you're not expecting it. You can change this by adding <meta http-equiv="X-UA-Compatible" tag if you want, though I actually found it makes life easier as it reduces the amount of different versions you've got to test against.
It is possible to embed an XBAP application into an IFrame, this is rather easy !!
The problem however is that it renders on top of anything within the web application. For example!
I have a menu in my web application which can collapse when I hover above it, but it will collapse UNDER the IFrame when it needs to collapse ON TOP of the IFrame with the XBAP Application in it.
I tried messing with the z-index but this does not fix anything!
It seems it has nothing to do with the IFrame, because when I put plain HTML into the IFrame it renders on top of the IFrame.
My last effort would be to put the XBAP Application in new browser window !! But it would be so much nicer to have it embedded within the application.
This guy seems to have the same problem
This is a known issue with controls/plugins that aren't rendered by the browser itself (these controls have their own windows, which are merely positioned inside the browser instead of composed within it). If you're willing to use Silverlight instead, there is a partial solution available with windowless controls that will allow you to intermix DOM content and managed code, but they have their own limitations. The upcoming Silverlight 4 can do even more than XBAPs as far as local trust/resource access...