JavaScript - 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 !!! Similar TutorialsFirst off I apologize If this is in the wrong section of this forum. So I got this concept that I think Is pretty cool. I dont know If there's anything like It out there, If there is, let me know. This is the concept: You click the icon and down pops a map in which there's a circle (like this: imgur: the simple image sharer) You can resize the circle and move it around. Underneath the map there's a box where you can type your search. Let's say you search for "puppies" in Brooklyn, New York The idea is that It'll scan all the coordinates inside the circle and search for photos in google images containing those coordinates in the GPS info (EXIF).This can be useful If you for example wants to search for photos taken in your city, or even in your neighborhood. I can see many uses for this. The thing is, I don't know any programming languages so I can't do this myself. I don't even know where to start. I'm looking for a kind soul to help me with this, I don't have any money so I'm not looking to pay anyone to do this for me. I just want some help getting started, or if someone would be kind enough to do It for free. (Though that Is very unlikely.) Thanks in advance! Sorry for my bad english, it is not my native language. Reply With Quote 01-30-2015, 04:24 PM #2 Philip M View Profile View Forum Posts Supreme Master coder! Join Date Jun 2002 Location London, England Posts 18,371 Thanks 204 Thanked 2,573 Times in 2,551 Posts Hope springs eternal in the human breast. – Alexander Pope, An Essay on Man You might as well say that you want to write a novel in French, but do not know anything about that language. Hi I am not sure if this is a javascript issue but, Google Chrome version : 10.0.680 with one particular website, when I click around the pages, chrome tries to download the page, so for example, say the page is called contact.html, it ends up trying to download a file calling it cr.download contact.html What is happening here - any ideas? Does that sound like a javascript issue to you? Thanks! Since the upgrade from chrome 9 to chrome 10 my script is showing an error in my variables when i use boolean expressions. they changed to version V8, Chrome's JavaScript engine. Here is the function function get_form_value(n){ e=document.getElementById(n); if ((e.value)&&(e.value != "")&&(!e.options)) return e.value; if ((e.selectedIndex)&&(e.selectedIndex>0) &&(e.options[e.selectedIndex].value !="")) return e.options[e.selectedIndex].value; // select if ((e.text)&&(e.text.value !="")) continue; if ((e.selectedIndex)&&(e.selectedIndex>0) &&(e.options[e.selectedIndex].text !="")) return e.options[e.selectedIndex].text; // select if ((e.checkbox)&&(e.checkbox.checked)) return true; return false; } When i run it it shows a syntax error: Can someone please help me fix this? I have a piece of code for adding categories to a shopping site, which was working fine but now doesn't submit after I made changes to try to validate the type image chosen for that category. I'll post the original and then changed code, anyone think they can see why it's not running? Code: function checkCategoryForm() { with (window.document.frmCategory) { if (isEmpty(catName, 'Enter category name')) { return; } else if (isEmpty(catDescription, 'Enter category description')) { return; } else { submit(); } } } Code: function getFileExtension(filename) { var ext = /^.+\.([^.]+)$/.exec(filename); return ext == null ? "" : ext[1]; } function checkCategoryForm() { with (window.document.frmCategory) { if (isEmpty(catName, 'Enter category name')) { return; } else if (isEmpty(catDescription, 'Enter category description')) { return; } else { if (getFileExtension(fileImage) = '.jpg' || '.jpeg' || '.png' || '.gif' ){ submit(); } else { alert("Enter this image format is not allowed, only .jpg, .png or .gif"); return; } } } } Thanks! The mounds of RegExp data will take me days to sift through can someone help me create a regular expression to find a file extension? (all characters after a period) I have already gotten this far: .+\. to find everything before and including the period; and I was hoping to integrate the caret to say everything but .+\. But I just can't get it to work... Note: I will be writing a file to the server with JScript ASP. The file name will be passed to the script that writes the file, and I want to make sure that in addition to removing any possible code from the line being written, that I also prevent an executable file from being created. I will be searching for certain extensions and returning if anything else is found. Hello. I have used the Firefox extension Linky for a very long time, it is one of my most used extensions bar none. However, one of the most attractive features of it broke somewhere in the updating from Firefox 3-4, as far as i know. I didn't find out about it until recently, due to never bothering to update past Firefox 3 until just a little while ago. industrial clay This feature was the 'Select already visited links' option, which also works in reverse, letting you unselect all links to pages you've already visited. (Or rather, have listed in your browser history) Now, i am a complete noob when it comes to JavaScript, and i have very little knowledge about this type of programming, so i have no chance to fix this myself. This, is the reason i came here. I hope someone will be able to take a quick look at this code, and maybe tell me how to fix it, or make a workaround, or something. I really want to get it working again. I am almost certain that the problem lies in this section of the code: Code: LinkySelect.prototype.checkVisited = function() { var gGlobalHistory = opener.Components.classes["@mozilla.org/browser/global-history;1"].getService(Components.interfaces.nsIGlobalHistory); var cbox = this.getChecked(document.getElementById("cvbox")); var selectlinks = document.getElementById("selectlinks"); var last = selectlinks.getRowCount(); for (var i = 0; i < last; i++) { var tmp = selectlinks.getItemAtIndex(i); if (gGlobalHistory.isVisited(tmp.getAttribute("value"))) { tmp.setAttribute("checked", this.setChecked(cbox)); } } this.updateInfo(); } Also, the Error Console reports this; Code: Error: opener.Components.classes['@mozilla.org/browser/global-history;1'] is undefined Source File: chrome://linky/content/select-links.js Line: 28 I hope that will tell someone something. I almost feels like it tells me something, but it's been years and years since i last tried to study this type of programming. Any help with this is appreciated. Thanks in advance for your time. Hello. I have used the Firefox extension Linky for a very long time, it is one of my most used extensions bar none. However, one of the most attractive features of it broke somewhere in the updating from Firefox 3-4, as far as i know. I didn't find out about it until recently, due to never bothering to update past Firefox 3 until just a little while ago. This feature was the 'Select already visited links' option, which also works in reverse, letting you unselect all links to pages you've already visited. (Or rather, have listed in your browser history) Now, i am a complete noob when it comes to JavaScript, and i have very little knowledge about this type of programming, so i have no chance to fix this myself. This, is the reason i came here. I hope someone will be able to take a quick look at this code, and maybe tell me how to fix it, or make a workaround, or something. I really want to get it working again. I am almost certain that the problem lies in this section of the code: Code: LinkySelect.prototype.checkVisited = function() { var gGlobalHistory = opener.Components.classes["@mozilla.org/browser/global-history;1"].getService(Components.interfaces.nsIGlobalHistory); var cbox = this.getChecked(document.getElementById("cvbox")); var selectlinks = document.getElementById("selectlinks"); var last = selectlinks.getRowCount(); for (var i = 0; i < last; i++) { var tmp = selectlinks.getItemAtIndex(i); if (gGlobalHistory.isVisited(tmp.getAttribute("value"))) { tmp.setAttribute("checked", this.setChecked(cbox)); } } this.updateInfo(); } Also, the Error Console reports this; Code: Error: opener.Components.classes['@mozilla.org/browser/global-history;1'] is undefined Source File: chrome://linky/content/select-links.js Line: 28 I hope that will tell someone something. I almost feels like it tells me something, but it's been years and years since i last tried to study this type of programming. Any help with this is appreciated. Thanks in advance for your time. Hi, I'm creating an extension on Firefox that wishes to parse the source of a page that the user is currently viewing for specific information. I've gotten as far as creating a simple extension with a button and when I click on it, it will show the url of the page I am currently viewing through: content.location.href All the examples I've seen so far concerning viewing the source forces you to either use the 'view-source:' convention or the 'xmlhttprequest' method. But these examples seems to be meant to be called within a web page and not an extension. When I cut and paste with these examples, I only get the source for the actual chrome portion of Firefox. I've tried modifying some of the examples to include 'content.document....etc' to reference what's being displayed in the browser, but it doesn't seem to work. Can anyone provide sample or reference code so I can extract the page source of my current window from an extension? Thanks! Hi, I am kinda new to java scripting and here is what i am trying to do. I have a folder "A" with 10 files, all with .txt extensions in it. I want a java script to open all the 10 files in the folder "A" and change the extensions to .js and save it in a folder "B". Can some one help. Thanks a lot in advance. Hi All, I have written a chrome extension which will redirect to all hrefs for a given source urls in current tab.. But i don't know why all of a sudden it stops executing after reaching some page. I am attaching my code as attachment. Can any one help me out. Thanks in advance. I have been trying to download the jquery code from this site, but the Firefox browser downloader says that it is unable to download it. Any ideas why this happens? Frank Hi there, On this website: http://www.lutanho.net/stroke/online.html it's allowed to "copy the games to your PC and play them offline". That's nice but how do I do that? I've tried to download/copy the game "WordGrid" to my PC but it didn't work. Help would be appreciated. Thanks in advance........... Can anyone give me the code for the following: Suppose there is a hyperlink for file downloading in a html document. If I click on the link a new pop up window will come up which will be in the form of a typical file download popup window and will ask me to either "open" or "save" or "cancel" or "more info" (just as it happens in a typical file download process where a file download popup is being thrown). Also my file(the file can be in any format---.doc,.pdf,.exe or whatever)resides in my local hard drive and when I click on the hyper link the file download popup will comeup and will give me the 4 options as mentioned above.It wont just display the content of the file to be opened in new popup window.It will explicitly give the 4 options for any type of file to be downloaded thru the hyperlink. This coding is to be done only and only with HTML and JAVASCRIPT . Can anyone help me by providing code for the above task. I'm trying to allow a user to download a file off my server without opening a new page. How would I do that with JavaScript? Thanks! I can write code to open a new window and write content into that window. e.g. Code: myWin = window.open('test.csv', 'myWin', '', true); mycontent = '< ... blah ... >'; myWin.document.writeln(my_content); myWin.document.close(); Does anyone know of a way to get the browser to download the content rather than display it, using javascript? Andrew. |