SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Zealot soapergem's Avatar
    Join Date
    Mar 2005
    Location
    Madison, WI
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IE7 security woes

    In one of my desktop apps, I am generating an HTML file, and then opening it in Explorer and immediately firing off a window.print() command, to allow my users to print the generated document. I also fire a window.close() command in the onafterprint event handler, so that the generated document will close itself as soon as it's done with the print dialog, thereby saving my users the extra click to close it (trying to, anyway...). I've run into two separate snags, though:

    #1) The gold bar appears on top in IE7, saying: To help protect your security, Internet Explorer has restricted this webpage from running scripts or ActiveX controls that could access your computer.

    The only reason I'm opening Explorer is to take advantage of its rendering engine to display and print the simple HTML I generated, so IE is not my main focus here, it's the desktop app that generates the HTML and calls IE that's really in charge.

    Because my users are running this application in the first place, I can assume that I have the ability to add or modify registry keys. So is there any way (any reg keys I can add, for instance?) to specifically tell IE that a local file at a given location (e.g. "C:\print.html") will always be safe to run JavaScript? (without prompts)

    #2) IE7 no longer lets the last remaining window close itself--not without being met with this prompt, anyway: The webpage you are vieiwing is trying to close the window. Do you want to close this window? In previous versions, this could be accomplished by setting window.opener to something non-empty, and then closing the window. IE7 now prevents this. So... has anyone found a workaround to this yet? Any way to close the window without the annoying prompt?

    My only other alternative is to use some sort of HTML printing utility, such as HTMLPrint--except I have yet to find anything with any sort of reasonable price for use with a commercial application. So I figured I'd just use something that all my users already have: IE. Except it's not the ideal solution with all the extra clicking involved. I could just tell them to hit "File - Print" manually and skip the JS altogether, but that too isn't very ideal.
    // useless crap about my relationships, philosophy,
    // theology, music and programming projects:

    my $blog = 'http://gordon-myers.com/';

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are you in control of the desktop applications? If so, what language are they in?

    You could be doing all of this, when there could be method much easier in the native language of the software.


  3. #3
    SitePoint Zealot soapergem's Avatar
    Join Date
    Mar 2005
    Location
    Madison, WI
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I am in control of this desktop application. I am generating the HTML as a report and then trying to print it, because I find HTML to be much more flexible and straight-forward than the report format my desktop language offers (it's a language called Clarion).

    I just happened to find an article on technet stating that by adding a particular, special comment tag one can force a webpage into the "Internet" zone and thereby circumvent the need to click on the gold bar. It it seems to work great! This is the tag:
    HTML Code:
    <!-- saved from url=(0014)about:internet -->
    But I'm still not sure how to force the window to close without a prompt. Maybe there's a solution that mixes Java and JavaScript?
    // useless crap about my relationships, philosophy,
    // theology, music and programming projects:

    my $blog = 'http://gordon-myers.com/';

  4. #4
    SitePoint Zealot soapergem's Avatar
    Join Date
    Mar 2005
    Location
    Madison, WI
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wait....just figured it out. If I save the file with the hta extension instead of html, it automatically gets extra privileges. I'll just do that. Then the script I ended up using was this:

    Code:
    <script type="text/javascript">
    window.onload = function() { window.print(); };
    window.onafterprint = function() { document.body.onfocus = function() { window.close(); }; };
    </script>
    I learned this after happening upon this forum post.
    // useless crap about my relationships, philosophy,
    // theology, music and programming projects:

    my $blog = 'http://gordon-myers.com/';


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •