JavaScript:打开 1+链接(没有内容)
你好, 这没有任何意义,但例如,如果我将文件下载到您的 /Downloads 文件夹并且我想运行 file:///.../Downloads/myfile1.txt 我可以直接执行:
window.location = "file:///.../Downloads/myfile1.txt;
但如果我说 10,或者它是由脚本生成的..我怎样才能有效地做到这一点..打开...myfile1.txt => ...myfile1.txt 我尝试使用文件名数组运行 jquery .Each() 语句..但它只打开第一个。
window.open();
这会给我留下数百个打开的窗口,这是我不想要的:/
顺便说一句。我没有执行 file:/// 但它不是 http:// 它的本地 URL 方案:)
谢谢!
HI,
This makes no sense, but for example if i downloaded a file to your /Downloads folder and i wanted to run file:///.../Downloads/myfile1.txt i could just go:
window.location = "file:///.../Downloads/myfile1.txt;
But if i had say 10, or it was generated by a script.. how could i do effectively this.. open ...myfile1.txt => ...myfile1.txt
I tried running a jquery .Each() statement with an array of file names.. but it only opens the first one.
window.open();
That would leave me with hundreds of open windows, which i dont want :/
BTW. I'm not doing the file:/// but its not a http:// its local URL Scheme :)
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想要做的是在一个窗口中一个接一个地打开一系列 URL,那么我会看到几个选项。
当您循环浏览列表时,您可以对每个窗口使用 window.open,但给窗口一个名称并为每个窗口使用相同的名称 - 这样它将打开一个额外的窗口并加载其中的每个 URL。请注意,它很可能在前一个有时间完成加载之前开始加载一个,除非您添加某种暂停或使用回调方法。
第二种方法是将它们依次加载到页面上的 iframe 中。同样的时间问题也适用。
If what you're trying to do is open a series of URLs, one after another, in a single window, then I see a couple of options.
When you loop through the list, you could use window.open on each one, but give the window a name and use the same name for each -- that way it would open a single extra window and load each URL in it. Note that it might well start loading one before the previous one has had time to finish loading, unless you add a pause of some kind, or use a callback approach.
The second approach is to load them, one after another, into an iframe on your page. Same timing issues apply.
这是行不通的,因为每个像样的浏览器都会阻止对本地文档的访问,无论是否下载。
This is not going to work because every decent browser will block access to local documents, downloaded or not.