Opening a file: URL with do JavaScript in Safari?

Hey, I’m not new to reading this site, but this is my first post. (Whee! I’m both kinda glad it’s taken this long to actually need the help of the gurus here, and am sad that I don’t generally have the answers others seek.)

Anyhow, I’m having a bit of an issue with trying to get Safari to open a URL with the file: protocol, using JavaScript from AppleScript. Wow, that’s confusing! Maybe the following will help clarify things! :smiley:


    tell application "Safari"
        activate
        make new document at end of documents
        do JavaScript "window.open('file://" & (POSIX path of tempFile) & "','" & friendlyName & "','height=" & windowHeight & ",width=" & windowWidth & ",toolbar=no,scrollbars=no,resizable=no,status=no,copyhistory=no,location=no,menubar=no');window.close();" in document 1
        -- The next line works fine!
        -- do JavaScript "window.open('http://www.google.com/','" & friendlyName & "','height=" & windowHeight & ",width=" & windowWidth & ",toolbar=no,scrollbars=no,resizable=no,status=no,copyhistory=no,location=no,menubar=no');window.close();" in document 1
    end tell

As you can probably guess, tempFile is a file with a bunch of HTML, and this is a fairly genericized routine which can spawn multiply-sized windows for different purposes.

I can live with the fact that a blank window pops up momentarily. The problem is that the line with the file:// doesn’t work, but the http:// line does! Is there a known problem with spawning windows with local file content from AppleScript? In fact, is there a better way to do this so that I can get the proper-sized window without any excess chrome? (The content is all Flash, so there’s no need for chrome since the user won’t be changing pages or even needing a status bar.)

In the mean time, I’m writing a second temporary file out which contains a window.open() JS link to the one I want to launch (and open it with Safari). It involves a bit more user interaction, but I suppose it will have to do for now. :frowning:

Oh, and yeah. I’ve verified that POSIX path of tempFile exists and contains the correct value. In fact, I write the following out to the second tempfile right now, so I know it’s correct:

<a href=\"javascript:window.open('file://" & (POSIX path of tempFile) & "','" & friendlyName & "','height=" & windowHeight & ",width=" & windowWidth & ",toolbar=no,scrollbars=no,resizable=no,status=no,copyhistory=no,location=no,menubar=no');window.close();\">Open Content Window</a>

Any suggestions as to what to try next are appreciated. Thanks in advance!