在javascript中生成一些xml,提示用户保存它 [英] Generate some xml in javascript, prompt user to save it

查看:75
本文介绍了在javascript中生成一些xml,提示用户保存它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在JavaScript中创建一个XML文档,然后出现一个保存对话框。

I'd like to make an XML document in JavaScript then have a save dialog appear.


  1. 如果必须点击它们就没关系保存之前可以发生。


  2. 这是*不是*如果我*使用IE来实现这一点(我根本不需要支持它) 。但是,Windows是必需的平台(因此,如果我只能在一个浏览器中执行此操作,则Firefox或Chrome是首选的浏览器。)


  3. 如果我需要,它不是* OK一个Web服务器。但相反,我不想要求JavaScript仅在本地文件上运行,即提升权限 - 如果可能的话。也就是说,我想在本地运行或在* static *主机上运行。但只是在当地就行了。


  4. 可以向后弯腰来做这件事。该文件不会很大,但互联网访问可能存在,或者根本不可能 - 或者根本不可能 - 请参阅(3)。

  1. It's OK if they have to click before the save can occur.
  2. It's *not* OK if I *have* to use IE to achieve this (I don't even need to support it at all). However, Windows is a required platform (so Firefox or Chrome are the preferred browsers if I can only do this in one browser).
  3. It's *not* OK if I need a web server. But conversely, I don't want to require the JavaScript to be run on a local file only, i.e. elevated privileges -- if possible. That is, I'd like to to run locally or on a *static* host. But just locally is OK.
  4. It's OK to have to bend over backwards to do this. The file won't be very big, but internet access might either be there, be spotty or just not be a possibility at all -- see (3).

到目前为止,我看到的唯一想法是将XML保存到iframe并保存该文档 - 但似乎你只能在IE中执行此操作?此外,我可以构建一个数据URI并将其放在一个链接中。我担心的是它只会在窗口中打开XML文件,而不是提示用户保存它。

So far the only ideas I have seen are to save the XML to an iframe and save that document -- but it seems that you can only do this in IE? Also, that I could construct a data URI and place that in a link. My fear here is that it will just open the XML file in the window, rather than prompt the user to save it.

我知道如果我需要JavaScript本地,我可以提高权限,只是直接保存文件(或希望导致出现保存对话框)。但是,我更喜欢一个我不需要提升权限的解决方案(即使只有Firefox 3.6解决方案)。

I know that if I require the JavaScript to be local, I can raise privileges and just directly save the file (or hopefully cause a save dialog box to appear). However, I'd much prefer a solution where I do not require raised privileges (even a Firefox 3.6 only solution).

如果这会冒犯任何人的敏感性,我会道歉(例如,不支持每个浏览器)。我基本上想要编写一个离线应用程序,考虑到需求的复杂性和可用的时间,Javascript / HTML / CSS似乎是最佳候选者。但是,我有这个能够保存必须克服的数据的单一要求才能选择这条开发线。

I apologize if this offends anyone's sensibilities (for example, not supporting every browser). I basically want to write an offline application and Javascript/HTML/CSS seem to be the best candidate considering the complexity of the requirements and the time available. However, I have this single requirement of being able to save data that must be overcome before I can choose this line of development.

推荐答案

这个 downloadify 脚本怎么样?

哪个基于Flash和jQuery,它可以提示您在计算机中保存文件的对话框。

Which is based on Flash and jQuery, which can prompt you dialog box to save file in your computer.

Downloadify.create('downloadify',{
  filename: function(){
    return document.getElementById('filename').value;
  },
  data: function(){ 
    return document.getElementById('data').value;
  },
  onComplete: function(){ 
    alert('Your File Has Been Saved!'); 
  },
  onCancel: function(){ 
    alert('You have cancelled the saving of this file.');
  },
  onError: function(){ 
    alert('You must put something in the File Contents or there will be nothing to save!'); 
  },
  swf: 'media/downloadify.swf',
  downloadImage: 'images/download.png',
  width: 100,
  height: 30,
  transparent: true,
  append: false
});

这篇关于在javascript中生成一些xml,提示用户保存它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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