Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-14-2011, 04:52 PM   PM User | #1
akhandal96
New to the CF scene

 
Join Date: Oct 2011
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
akhandal96 is an unknown quantity at this point
How to download files using a chrome extension?

I want to download text file generated in a textarea

here my download.php file code structure goes :

<?php

if(empty($_POST['filename']) || empty($_POST['content'])){
exit;
}

$filename = preg_replace('/[^a-z0-9\-\_\.]/i','',$_POST['filename']);

header("Cache-Control: ");
header("Content-type: text/plain");
header('Content-Disposition: attachment; filename="'.$filename.'"');

echo $_POST['content'];

?>

and the javascript used


(function($){

$.generateFile = function(options){

options = options || {};

if(!options.script || !options.filename || !options.content){
throw new Error("Please enter all the required config options!");
}

var iframe = $('<iframe>',{
width:1,
height:1,
frameborder:0,
css:{
display:'none'
}
}).appendTo('body');


and the script.js

$(document).ready(function(){

$('#download').click(function(e){

$.generateFile({
filename : 'export.txt',
content : $('textarea').val(),
script : 'download.php'
});

e.preventDefault();
});

by these assets i created a web page consisting a TEXTAREA , by entering some text on the textarea and clicking on the download button , a text files is generated and downloaded on the user's system, I packed the source code as a CRX file to use it as a CHROME extension, but while using the extension,the files are'nt generated, while the webpage works absolutely fine !!!
akhandal96 is offline   Reply With Quote
Reply

Bookmarks

Tags
chrome, html, javascript, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:30 PM.


Advertisement
Log in to turn off these ads.