简体   繁体   中英

running JavaScript on a file:/// page (opened with Chrome on Windows 7)

the idea: I'd like to make a very lightweight alternative to Windows Explorer for sorting and viewing my pictures, and the best approach (if it is possible) that I can think of is using javascript and jQuery to parse the html that is generated when I enter a file:/// url into Chrome.

possible approach: The only way I can think to do this is to have a html page linking to my script, with an iframe containing the file:/// generated page, then accessing the list of files from there.

EDIT example of the possible approach. explore.js would have a script that accesses DOM elements inside myFrame and generates a custom view of the directory

<!DOCTYPE html>
<html>
  <head>
    <script src="explore.js" type="text/javascript"></script>
    <title>My Explorer</title>
  </head>
  <body>
    <iframe id="myFrame" src="file:///c:/my/pics/directory"></iframe>
  </body>
</html>

questons: I've played around a little with no success - is it possible to access an iframe in this way (and how would this be approached)? Is there another approach that would give me something with similar simplicity, customizability and portability?

Through some explorations I've found that Chrome's current behaviour is not to allow access to the DOM of an iframe from the local domain, regardless of whether the parent frame is local. I'll have to look at another approach.

Some browsers won't let you display local files in an iframe for security reasons (though this may be waived if the parent document is local, too).

You can absolutely access the iframe 's DOM .

Have you considered running a webserver on your computer and using server-side scripting instead?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM