在 Firefox 中,使用 Javascript 写入文件? [英] In Firefox, Write to a File using Javascript?

查看:19
本文介绍了在 Firefox 中,使用 Javascript 写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:-我创建了一个安装设置(本地),它返回一个 URL,例如:- ved.test.com,它映射到 IP 11.22.33.44.因此,为了在安装后可以访问Web 应用程序,用户必须在C:WINNTsystem32driversetc"目录下的hosts 文件中明确创建一个条目.

Situation:- I have created a installation setup(local) that returns a URL eg:- ved.test.com which is mapped to an IP 11.22.33.44. Thus to make the web application accessible after installation, user has to make an entry in the hosts file under "C:WINNTsystem32driversetc" directory explicitly.

方法:-安装应用程序完成后,应用程序使用 Javascript 写入文件.

Approach:- After the installation application gets completed, application writes the file using Javascript.

问题:-IE 支持使用 Javascript 编写文件.我需要 Firefox 的解决方案.使用的代码:-

Problem:- Writing a File using Javascript is supported in IE. I need a Solution for Firefox. Code used:-

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Write To A File</title>
<script language="javascript">
    function WriteToFile()
    {
    /* The below statement is supported in IE only */
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var s = fso.CreateTextFile("C:\Test.txt", true);
    s.WriteLine('IE Supports Me!');
    s.Close();
    }
</script>
</head>
    <body onLoad="WriteToFile()">
</body>
</html>

还参考了 SO 中的链接:-如何使用 JavaScript 读写文件

Have also refered the link in SO:- How to read and write into file using JavaScript

请提供一个支持使用在Firefox浏览器中运行的Javascript编写文件的解决方案.

Kindly provide a solution that supports writing a file using Javascript that runs in Firefox browser.

提前致谢.

推荐答案

出于明显的安全原因,您不能这样做.JavaScript 无法访问文件系统......在 IE 中它不是 JavaScript,而是 ActiveX 这样做......它只是公开了一个 JavaScript API.

You can't do this, for hopefully obvious security reasons. JavaScript has no access to the file system...in IE it's not JavaScript, but ActiveX doing this...it just has a JavaScript API exposed.

问题不在于 Firefox 不这样做……而是 IE 曾经允许这样做:)

The problem isn't that Firefox doesn't do this...it's that IE ever allowed it :)

这篇关于在 Firefox 中,使用 Javascript 写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆