在 file:/// 页面上运行 JavaScript(在 Windows 7 上使用 Chrome 打开)
想法: 我想制作一个非常轻量级的 Windows 资源管理器替代方案来排序和查看我的图片,我能想到的最佳方法(如果可能的话)是使用 javascript 和 jQuery 来解析我输入时生成的 html Chrome 中的 file:/// url。
可能的方法: 我能想到的唯一方法是让一个 html 页面链接到我的脚本,并使用一个包含 file:/// 生成页面的 iframe,然后从那里访问文件列表。
编辑 可能方法的示例。 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>
问题: 我尝试了一点但没有成功 - 是否可以通过这种方式访问 iframe(以及如何实现)?是否有另一种方法可以为我提供类似的简单性、可定制性和可移植性?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过一些探索,我发现Chrome当前的行为是不允许从本地域访问iframe的DOM,无论父框架是否是本地的。我得看看另一种方法。
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.
出于安全原因,某些浏览器不允许您在
iframe
中显示本地文件(尽管如果父文档也是本地文档,则可以放弃此操作)。您绝对可以访问
iframe
的DOM。您是否考虑过在计算机上运行网络服务器并使用服务器端脚本?
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?