强制& quot;另存为&"通过jQuery GET对话框 [英] Forcing "Save As" dialog via jQuery GET

查看:88
本文介绍了强制& quot;另存为&"通过jQuery GET对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的test.php文件代码上调用jQuery"GET".

I'm calling a jQuery "GET" on the test.php file code below.

我正在尝试让脚本在生成的test.ini文件上弹出另存为"对话框,以允许将其保存在本地.但是,尽管我可以将结果回显到jQuery,但似乎无法弹出另存为"对话框.

I'm trying to get the script to pop a "Save As" dialog on the resulting test.ini file to allow it to be saved locally. However, although I can echo the result back to the jQuery fine, I can't seem to pop the "save as" dialog.

更新:由于采用了以下解决方案,我将$ .get更改为window.location.replace.

Update: Thanks to the solutions below, I just changed my $.get to a window.location.replace.

$('#test').click(
    function()
    {
        //$.get('<?php echo get_bloginfo('template_directory') ?>/test.php');
        window.location.replace("<?php echo get_bloginfo('template_directory') ?>/test.php");

    }
);

推荐答案

您无法获得ajax请求来显示另存为"对话框,但是您可以做的是在页面中插入一个隐藏的iframe元素,然后将该iframe的源设置为您要用户下载的网址.瞧,有您的另存为.

You can't get an ajax request to show a "Save As" dialog, but what you CAN do is insert a hidden iframe element in the page, then set the source of that iframe to the url you want the user to download. Voila, there's your Save As.

这是一个粘贴示例:

$('a#linky').click(function(){
  var iframe = document.createElement("iframe"); 
  iframe.src = 'http://example.com/branding.zip'; 
  iframe.style.display = "none"; 
  document.body.appendChild(iframe);
  return false;
});

这篇关于强制&amp; quot;另存为&amp;&quot;通过jQuery GET对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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