Printing fieldsets in firefox

后端 未结 3 366
灰色年华
灰色年华 2020-12-09 19:11

I\'ve been adding some new css to an existing project (using media=\"print\") in the page header. It\'s going smooth and (for once!) IE is giving nice, expected results, but

相关标签:
3条回答
  • 2020-12-09 19:23

    As I guessed, it's still broken in the latest Nightly.

    You could try to do something similar to IE Print Protector (aka the widely used html5shiv).

    http://www.iecss.com/print-protector/#how-it-works

    To display elements correctly in print, IE Print Protector temporarily replaces HTML5 elements with supported fallback elements (like div and span) when you print. IE Print Protector also creates a special stylesheet for these elements based on your existing styles; this means you can safely style HTML5 elements by element name in links, styles, @imports and @media. Immediately after, IE Print Protector restores the original HTML5 element to the page, right where you left it. Any references to those elements and any events on those elements will remain intact.

    Firefox now supports onbeforeprint.

    So, when onbeforeprint is fired, you could change the fieldsets for divs, or something.

    I'm not sure how viable this is, and it sure sounds complicated.

    0 讨论(0)
  • 2020-12-09 19:32

    My JQuery solution for FF:

    <script type='text/javascript'>
        $(window).bind('beforeprint', function(){
            $('fieldset').each(
                function(item)
                {
                    $(this).replaceWith($('<div class="fieldset">' + this.innerHTML + '</div>'));
                }
            )
        });
        $(window).bind('afterprint', function(){
            $('.fieldset').each(
                function(item)
                {
                    $(this).replaceWith($('<fieldset>' + this.innerHTML + '</fieldset>'));
                }
            )
        });
    </script>
    
    0 讨论(0)
  • 2020-12-09 19:39

    Check out this jQuery hack I just wrote to solve this issue, figured I'd share even though I'm a bit late. You can change "printEnclosure" to an HTML tag I believe and the CSS at the end is obviously optional.

    <div id="printEnclosure">
    <fieldset>
    <legend>TEST</legend>
    
    Test Content goes here...
    </fieldset>
    </div>
    
    <script type="text/javascript">
    /* <![CDATA[ */
    $(document).ready(function()
    {
            var i = 0;
            $('#printEnclosure').find('fieldset').each(function()
            {
                i++;
                $(this).replaceWith('<div id="convertedfieldset'+i+'">'+$(this).html()+'</div>');
                $('div#convertedfieldset'+i).css('display','inline').css('text-align','left');
            });
    });
    /* ]]> */
    </script>
    
    0 讨论(0)
提交回复
热议问题