0

I'm generating an HTML document and I'm using CSS to number paragraphs this way:

    p.numerado:before {
        content: counter(numerado) ". ";
        counter-increment: numerado;
        display: inline-block;
        width: 25mm;
        font-weight: normal;
    }

    p.numerado {
        text-indent: 0mm;
        text-align: justify;
        font-family: "Times New Roman, Times, serif";
        font-size: 11pt;
        margin-top: 0;
        margin-bottom: 0.2em;
        line-height: 1.2em;
        font-weight: normal;
    }
  • EDIT: this is not a duplicate from :after and :before css pseudo elements hack for IE 7 because my problem involves paragraph numeration instead of image showing, plus I don't want to embed scripts in my HTML for it will cause its rejection by the webservice I'm going to submit it.

However, I need to show a preview of this inside a .NET WebBrowser control, which renders HTML in IE7 fashion, and then the styles above don't work, that is, the paragraphs with numerado class aren't numbered neither indented.

Since the final destination of the HTML document is current Firefox, and I'm not willing to change Windows Registry just to modify WebBrowser control behavior, I'd like to know if there is an alternative CSS I can use, just for the sake of showing the preview inside WebBrowser with the closest as possible style of the final result, regarding to the numeration and indenting of those paragraphs.

This is how it renders in Firefox: Firefox rendering

This is how it renders in WebBrowser(IE7) IE7 rendering

Nimantha
  • 6,405
  • 6
  • 28
  • 69
VBobCat
  • 2,527
  • 4
  • 29
  • 56
  • 1
    "the styles above don't work" is pretty vague. Specifically, what is not displaying the way you expect? Since IE7 is obsolete, it's unlikely someone will be able to test this for you. Maybe a screenshot comparing your IE7 and FF output would help? Ultimately, you shouldn't need to worry about IE7 in 2018. – jmargolisvt Mar 18 '18 at 13:55
  • @jmargolisvt, you are right, I edited the post to clarify. I'd like to agree with you I shouldn't need to worry, but this is caused by a specific scenario I am not able to change now (that is, I need to deploy a Winforms .NET application in machines where users won't have rights to perform registry changes needed to make WebBrowser to behave as a newer version of IE, and MS by its turn never bothered to make this component easier to setup regarding to rendering modes). Thank you. – VBobCat Mar 18 '18 at 14:14
  • I don't get it. If this document is intended to be displayed in Firefox, why do you care what it looks like in a WinForms WebBrowser control of all things? – BoltClock Mar 18 '18 at 14:14
  • @BoltClock, because its preview must be shown in a window from the application that generates the document (it is a Winforms .NET app), and then the HTML will be submitted to a webservice and will be shown in Firefox, but for other users. – VBobCat Mar 18 '18 at 14:16
  • Well, that's rather unfortunate. How does the application work with your supplied CSS? And does it allow you to save or copy the generated HTML with which you can preview in your favorite browser? – BoltClock Mar 18 '18 at 14:26
  • @BoltClock my application generates the whole HTML, using the same CSS the target web application generates in its own documents. Since my knowledge in CSS is shallow, I decided to ask this question before surrendering to the need of tweaking the entire document into a preview-only-ie7-compatible version, which, it seems, I'll have to do anyway. – VBobCat Mar 18 '18 at 14:34
  • 1
    Possible duplicate of [:after and :before css pseudo elements hack for IE 7](https://stackoverflow.com/questions/4181884/after-and-before-css-pseudo-elements-hack-for-ie-7) – jmargolisvt Mar 18 '18 at 15:08
  • IE7 is **years** past its End-Of-Life for even extended support and critical security features. Please consider ending support for it in your websites and applications. – TylerH Mar 18 '18 at 19:02
  • @TylerH, is it enough to set a higher version as I did in my answer? – VBobCat Mar 18 '18 at 19:20
  • @VBobCat I'm not sure what you mean. I'm talking about not writing code explicitly for old/unsecure browsers. The solution to "X doesn't work in IE7" should always be "good. no one should be using IE7 anymore" Or IE8, 9, or 10, either. – TylerH Mar 18 '18 at 19:25
  • @TylerH, as much as you are completely right, what should I do if I need to render HTML inside a Winforms Window? I can't abandon Winforms at this moment. And this need comes to answer a specific issue: before, I was saving the .htm file in temp and just calling `Process.Start` over it. Then this user had managed to set MS Word as default handler for .htm, that user kept losing the browser among the 237 windows he kept open at the same time... Sorry, I know my solution is far from ideal, but... – VBobCat Mar 18 '18 at 19:30
  • 1
    @VBobCat To be clear I'm not trying to shut you down or say your question shouldn't be answered. I know a lot of developers have to develop for a specific environment and all that. But I would be remiss if I did not also leave a warning for you or other readers in case they do not know that IE7 is old/deprecated/unsecure. :-) – TylerH Mar 18 '18 at 19:32

1 Answers1

0

Ok, I sort of solved it running the method below before loading the WebBrowser component. It is based on this thread. Let's just hope it won't crash in users' stations with no admin rights:

Private Sub AdjustIE()
    Dim appName = Process.GetCurrentProcess().ProcessName + ".exe"
    Dim desiredversionKey = 8000
    Try

        Dim RegKey32 As RegistryKey = Nothing
        RegKey32 = Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", True)
        If RegKey32 Is Nothing Then
            RegKey32 = Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION")
        End If
        Dim versionKey32 = CInt("0" & CStr(RegKey32.GetValue(appName)))
        If versionKey32 < desiredversionKey Then
            RegKey32.SetValue(appName, desiredversionKey, RegistryValueKind.DWord)
        End If
        RegKey32.Close()
    Catch ex As Exception
        If Debugger.IsAttached Then Stop
    End Try

    If (Environment.Is64BitProcess) Then
        Try
            Dim RegKey64 As RegistryKey = Nothing
            RegKey64 = Registry.CurrentUser.OpenSubKey("SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", True)
            If RegKey64 Is Nothing Then
                RegKey64 = Registry.CurrentUser.CreateSubKey("SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION")
            End If
            Dim versionKey64 = CInt("0" & CStr(RegKey64.GetValue(appName)))
            If versionKey64 < desiredversionKey Then
                RegKey64.SetValue(appName, desiredversionKey, RegistryValueKind.DWord)
            End If
            RegKey64.Close()
        Catch ex As Exception
            If Debugger.IsAttached Then Stop
        End Try
    End If
End Sub
VBobCat
  • 2,527
  • 4
  • 29
  • 56