简体   繁体   English

在file:///页面上运行JavaScript(在Windows 7上使用Chrome打开)

[英]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. 想法:我想为Windows资源管理器提供一种非常轻巧的替代品来排序和查看图片,并且我能想到的最佳方法(如果可能)是使用javascript和jQuery来解析生成的html。当我在Chrome中输入file:///网址时。

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. 可能的方法:我能想到的唯一方法是让html页面链接到我的脚本,而iframe包含file:///生成的页面,然后从那里访问文件列表。

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 explore.js将具有一个脚本,该脚本可访问myFrame DOM元素并生成目录的自定义视图

<!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)? questons:我周围有点打不出来-这可能访问一个iframe以这种方式(以及如何将这种接洽)? 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. 通过一些探索,我发现Chrome的当前行为是不允许从本地域访问iframe的DOM,无论父框架是否是本地的。 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). 出于安全原因,某些浏览器不允许您在iframe显示本地文件(尽管如果父文档也是本地的,则可以免除此操作)。

You can absolutely access the iframe 's DOM . 您可以绝对访问iframe的DOM

Have you considered running a webserver on your computer and using server-side scripting instead? 您是否考虑过在计算机上运行网络服务器并改用服务器端脚本?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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