JavaScript - Problem With File Download Script
Hi Guys,
I am trying to create a way for my users to download some code dynamically from my web page via a file download. Below is the code that i have written so far. It seems to be dying on the iframe but i'm not sure why. Here is my jquery trigger which is inside my onreadystate function. Code: $('#export_txt').click(function(e){ alert(LPAjax.ajaxurl + "/download.php"); $.generateFile({ action : "download_txt", filename : "exportme.txt", content : $("#ticket_window").html(), script : LPAjax.ajaxurl + "/download.php" }); e.preventDefault(); }); and here is the code i am using to process the post. Code: (function($){ // Creating a jQuery plugin: $.generateFile = function(options){ options = options || {}; if(!options.script || !options.filename || !options.content){ throw new Error("Please enter all the required config options!"); } alert("Inside Function"); // Creating a 1 by 1 px invisible iframe: var iframe = $('<iframe>',{ width:1, height:1, frameborder:0, css:{ display:'none' } }).appendTo('body'); var formHTML = '<form action="" method="post">'+ '<input type="hidden" name="filename" />'+ '<input type="hidden" name="content" />'+ '</form>'; // Giving IE a chance to build the DOM in // the iframe with a short timeout: setTimeout(function(){ // The body element of the iframe document: var body = (iframe.prop('contentDocument') !== undefined) ? iframe.prop('contentDocument').body : iframe.prop('document').body; // IE alert(" We are almost there"); body = $(body); // Adding the form to the body: body.html(formHTML); alert("added form to page"); var form = body.find('form'); form.attr('action',options.script); form.find('input[name=filename]').val(options.filename); form.find('input[name=content]').val(options.content); alert("submitting form"); // Submitting the form to download.php. This will // cause the file download dialog box to appear. form.submit(); },50); }; })(jQuery); it seems to be dying on this line. Code: var body = (iframe.prop('contentDocument') !== undefined) Any suggestions? Thanks in advance. Similar TutorialsI 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 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. First, let me clarify. I'm still a JS noob, so feel free to dummy-proof your answers By my understanding, if I want to use a given JS on multiple pages, I need to call for that script in each page. If I understand correctly, it then downloads it, and the functionality is then available to that given page. Now, presuming that I've got that at least mostly correct, it seems like there should be a way to just download it once, and use it till the session is over. My thinking is to call for the heavy JS's on the welcome page after a succeful login, and then not have to slow down each and every page by calling for those same scripts. Is this common, or at least possible? Are there specific reasons to not do this? Thanks-a-bunch, ~ Mo hi, I have a website which is available on internet and uses lot of javascript code. Someone recently reported a bug and I fixed it in a javascript file. Now I want to move this updated js file on my server. but I am confused, how will this fix now be downloaded on every user's browser when they access website the next time? Is the download to client machine dependent on browser settings? could it be possible that some customer machine has latest file and some do not. How do I force file to download on client machine independent of client browser settings? thank u Hi, I am new to the forum so apologies if I have posted in wrong place ! I have used a script in my site but would like to get the .wav file to loop can anyone advise how to change the script to allow this, I am not very good with Javascript !!!! Here is the Javascript: <!-- Functions Code Block Start--> <script> /* Here we are creating two functions. The first to start a sound object playing and the second to stop a sound object from playing. */ // // This function, when called will play the sound object function EvalSoundPlay(soundobj) { var thissound= eval("document."+soundobj); thissound.Play(); } // This function, when called will stop the sound object function EvalSoundStop(soundobj) { var thissound= eval("document."+soundobj); thissound.Stop(); } </script> <!-- Functions Code Block End--> <!-- Here we are embedding the sound file/s. We give each embedded sound a 'name' that we can refer to in a JavaScript event call. ----- // Note: You can have multiple sounds embedded but remember that each sound requires a different 'name' and each would require its own set of play/pause buttons. --> <embed src="Smooth_Ambience.wav" autostart=false width=0 height=0 name="sound1" enablejavascript="true" /> <!-- This is an example of a second embedded sound. --> <embed src="jingle_bell_rock.mp3" autostart=false width=0 height=0 name="sound2" enablejavascript="true" /> And Here is my HTML <div class="musicPlayer"> <img src="../Assets/Images/Global/play-button.png" alt="music play button" width="40" height="40" onClick="EvalSoundPlay('sound1')"/><img src="../Assets/Images/Global/stop_button.png" alt="music stop button" width="40" height="40" onClick="EvalSoundStop('sound1')"/> </div><!-- End .musicPlayer --> Thanks, Nick C Greetings! I have this script and I want to take out the part below the /////////////////////////// up to the buildMenu(); statement. I would dynamically create the menu list with php. Problem is I don't know javascript that well This is its own .js file not a script within the head section of the page. Code: <!-- /* Configure menu styles below NOTE: To edit the link colors, go to the STYLE tags and edit the ssm2Items colors */ YOffset=150; // no quotes!! XOffset=0; staticYOffset=30; // no quotes!! slideSpeed=20 // no quotes!! waitTime=100; // no quotes!! this sets the time the menu stays out for after the mouse goes off it. menuBGColor="black"; menuIsStatic="yes"; //this sets whether menu should stay static on the screen menuWidth=150; // Must be a multiple of 10! no quotes!! menuCols=2; hdrFontFamily="verdana"; hdrFontSize="2"; hdrFontColor="white"; hdrBGColor="#170088"; hdrAlign="left"; hdrVAlign="center"; hdrHeight="15"; linkFontFamily="Verdana"; linkFontSize="2"; linkBGColor="white"; linkOverBGColor="#FFFF99"; linkTarget="_top"; linkAlign="Left"; barBGColor="#444444"; barFontFamily="Verdana"; barFontSize="2"; barFontColor="white"; barVAlign="center"; barWidth=20; // no quotes!! barText="SIDE MENU"; // <IMG> tag supported. Put exact html for an image to show. /////////////////////////// // ssmItems[...]=[name, link, target, colspan, endrow?] - leave 'link' and 'target' blank to make a header ssmItems[0]=["Menu"] //create header ssmItems[1]=["Dynamic Drive", "http://www.dynamicdrive.com", ""] ssmItems[2]=["What's New", "http://www.dynamicdrive.com/new.htm",""] ssmItems[3]=["What's Hot", "http://www.dynamicdrive.com/hot.htm", ""] ssmItems[4]=["Message Forum", "http://www.codingforums.com", "_new"] ssmItems[5]=["Submit Script", "http://www.dynamicdrive.com/submitscript.htm", ""] ssmItems[6]=["Link to Us", "http://www.dynamicdrive.com/link.htm", ""] ssmItems[7]=["FAQ", "http://www.dynamicdrive.com/faqs.htm", "", 1, "no"] //create two column row ssmItems[8]=["Email", "http://www.dynamicdrive.com/contact.htm", "",1] ssmItems[9]=["External Links", "", ""] //create header ssmItems[10]=["JavaScript Kit", "http://www.javascriptkit.com", ""] ssmItems[11]=["Freewarejava", "http://www.freewarejava.com", ""] ssmItems[12]=["Coding Forums", "http://www.codingforums.com", ""] buildMenu(); //--> I don't know the syntax to do something like this: Code: <!-- /* Configure menu styles below NOTE: To edit the link colors, go to the STYLE tags and edit the ssm2Items colors */ YOffset=150; // no quotes!! XOffset=0; staticYOffset=30; // no quotes!! slideSpeed=20 // no quotes!! waitTime=100; // no quotes!! this sets the time the menu stays out for after the mouse goes off it. menuBGColor="black"; menuIsStatic="yes"; //this sets whether menu should stay static on the screen menuWidth=150; // Must be a multiple of 10! no quotes!! menuCols=2; hdrFontFamily="verdana"; hdrFontSize="2"; hdrFontColor="white"; hdrBGColor="#170088"; hdrAlign="left"; hdrVAlign="center"; hdrHeight="15"; linkFontFamily="Verdana"; linkFontSize="2"; linkBGColor="white"; linkOverBGColor="#FFFF99"; linkTarget="_top"; linkAlign="Left"; barBGColor="#444444"; barFontFamily="Verdana"; barFontSize="2"; barFontColor="white"; barVAlign="center"; barWidth=20; // no quotes!! barText="SIDE MENU"; // <IMG> tag supported. Put exact html for an image to show. /////////////////////////// // ssmItems[...]=[name, link, target, colspan, endrow?] - leave 'link' and 'target' blank to make a header include menu-file buildMenu(); //--> Not really sure how to go about this Thanks for any help in advance! Hey guys I'm trying to figure out the best/easiest/fastest way to accomplish this task: I have a csv file I need to generate an HTML item description based on the infomation in this csv Here is an example: ITEM NAME, ITEM TITLE, MANUFACTURE, CONDITION, LAST PHOTO LINK, I would then need the script to generate the HTML markup AND I will also need the script to determine if the last photo in the list is photo "c" and then create the links for photos a-c ie: <b>ITEM NAME<b><br> <i>ITEM TITLE</i><br> <img src="photoa.jpg"><img src="photob.jpg"><img src="photoc"><br><br> ect.... I'm sure there is a good way to do this I'm just not sure which language will be the easiest to do it in. If there is a way to use java I am most familiar with java. I would also like the script to export the data in a csv file as well if possible. Thanks for any advice guys! Please if you have any reference links post them! hi i need to merge this code in 1 file the files in attach the code for auto popup window withe cookis i need merge it for switch it to vb mood i think the job very easy but am not java script cooder I want to insert "mu" character after "Output in <here i want to insert mu character> " in following JavaScript line Code: paper = new Raphael(document.getElementById('dialog2'), 500, 500); var a= paper.text(345,384,"Output in <here i want to insert mu character> ").attr({'font-size':13}); Yes - I need a script that will validate user input against a text file - exactly like the one in the left sidebar at http://www.oilpatchfuel.com/Pages/Welcome.aspx titled "Delivery Area". Thanks! Hello, i'm trying to insert a dynamic js file which contains multiple functions in it (for the example : function x, function y) and it seems that my google chrome doesn't really like it so much is there anyway you know i can bypass it and make it work and both web browsers code examples: // this is where the js file supposed to go <script id="ScriptFile"> </script> //1.js contains function x and function y document.getElementById('ScriptFile').src = "/Mysite/js/1.js" later on i need to preform some actions with function x & y. Couple more issues i need to explain first there are number of js files (1,2,3 .... n ) which all contain the same functions but with different data so i cant register them hard-coded if i type the function x into the "ScriptFile" block, it does work.. its not the function problem. same goes if i include it as source in the "ScriptFile" block (<script id="ScriptFile" src="/Mysite/js/1.js") this only gives me an error while using chrome, works perfectly fine under explorer the error says it cant find function x. thanks alot! Hello all. This script is working fine in IE7 but FF is complaining about undeclared variables. Can anybody assist to get this working in FF or do I need a new script? Any and all advice is welcome. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test ZOOM</title> <script type="text/javascript"> //Image zoom in/out script- by javascriptkit.com //Visit JavaScript Kit (http://www.javascriptkit.com) for script //Credit must stay intact for use var zoomfactor=0.05 //Enter factor (0.05=5%) function zoomhelper(){ if (parseInt(whatcache.style.width)>10&&parseInt(whatcache.style.height)>10){ whatcache.style.width=parseInt(whatcache.style.width)+parseInt(whatcache.style.width)*zoomfactor*prefix whatcache.style.height=parseInt(whatcache.style.height)+parseInt(whatcache.style.height)*zoomfactor*prefix } } function zoom(originalW, originalH, what, state){ if (!document.all&&!document.getElementById) return whatcache=eval("document.images."+what) prefix=(state=="in")? 1 : -1 if (whatcache.style.width==""||state=="restore"){ whatcache.style.width=originalW+"px" whatcache.style.height=originalH+"px" if (state=="restore") return } else{ zoomhelper() } beginzoom=setInterval("zoomhelper()",100) } function clearzoom(){ if (window.beginzoom) clearInterval(beginzoom) } </script> </head> <body> <!-- CHANGE 99 to your image width, 100 to image height, and "office_map" to your image's name--> <a href="#" onmouseover="zoom(100,63,'office_map_6','in')" onmouseout="clearzoom()">Zoom In</a> | <a href="#" onmouseover="zoom(100,63,'office_map_6','restore')">Normal</a> | <a href="#" onmouseover="zoom(120,60,'office_map_6','out')" onmouseout="clearzoom()">Zoom Out</a> <div style="position:relative;width:420;height:300"> <div style="position:absolute"><img name="office_map_6" src="images/office_map_6.gif" width="100" height="63"> </div> </div> </body> </html> low tech I have a problem I just can't seem to solve. Seems to be an interference of two scripts. But have checked no duplicate function names or variables. Tried altering script order too. The one that breaks, breaks on this line: $('*[@title^="ajax:"]').each(function(index){ ... which I don't fully understand. The expression is a jQuery loop thing I believe. index seems to be null. I can't see where index is defined. What the code at this point aims to do is check for the phrase ajax: in all links on the page and do some manipulation so that the contents of the link are shown in a a tooltip. The problem is not about ajax. The full script is he http://www.javascriptkit.com/script/...xtooltip.shtml The problem occurs when the page includes the editor script, such as he http://www.tji-java-ide.com/beijing/...blogs&Itemid=1 The links on the top of the page work fine when there is no editor present, such as he http://www.tji-java-ide.com/beijing/...tpage&Itemid=1 confused:hope its the right place to post a newbie here . but i have a problem with a firefox accepting a script that i wrote it works on exploer but not on firefox onclick="javascript:if (this.parentNode.parentNode.nextSibling.style.display !='block') this.parentNode.parentNode.nextSibling.style.display ='block'; else this.parentNode.parentNode.nextSibling.style.display ='none';" hope u can help me thx I have an age script running in the attachment below. It works fine for numbers such as 1 22 1980. Code: if ((input.search(/\b([1-9]|[12][0-9]|3[01])\b/)!= -1) && (input.search(/\b([1-9]|1[0-2])\b/)!=-1) && (input.search(/\b(19[0-9]{2}|200[0-9]|201[01])\b/)!= -1)) { function getBirth() { var now = new Date(); var myMatchy = input.match(/\b(19[0-9]{2}|200[0-9]|201[01])\b/); var myMatchm = input.match(/\b([1-9]|1[0-2])\b/) var myMatchd = input.match(/\b([1-9]|[12][0-9]|3[01])\b/); var year = myMatchy[0]; var month = myMatchm[0]; var day = myMatchd[0]; var today = { "year" : now.getFullYear(), "month": now.getMonth()+1, "day" : now.getDate() } var age = today["year"] - year; if (month > today["month"]) age--; else if (month == today["month"]) if (day > today["day"]) age-- return age; } document.result.result.value = "Your age is "+getBirth()+"."; return true;} However, if someone writes out the month it doesn't. Such as January 22 1980. I did a work-around by inserting the month value. Highlighted below. But that means I would have to duplicate this lengthy code 12 times for each month of the year. Anybody know a better way to handle this? You can test it in the small attachment below. Any help would be appreciated. Code: if ((input.search(/\b([1-9]|[12][0-9]|3[01])\b/)!= -1) && (input.search(/(january)/)!= -1) && (input.search(/\b(19[0-9]{2}|200[0-9]|201[01])\b/)!= -1)) { function getJan() { var now = new Date(); var myMatchy = input.match(/\b(19[0-9]{2}|200[0-9]|201[01])\b/); var myMatchd = input.match(/\b([1-9]|[12][0-9]|3[01])\b/); var month = 0; var year = myMatchy[0]; var day = myMatchd[0]; var today = { "year" : now.getFullYear(), "month": now.getMonth()+1, "day" : now.getDate() } var age = today["year"] - year; if (month > today["month"]) age--; else if (month == today["month"]) if (day > today["day"]) age-- return age; } document.result.result.value = "Your age is "+getJan()+"."; return true;} Hi there, Im very new to all this and have only been working with scripts for a few days, so simple pointers would be greatly appriciated. My problem; I play an online strategy game where i can use scripts to help my game play. There is a quick bar at the top of the game screen which i can add scripts to. When editing the bar there are 3 options. 1. Name, 2. Image URL, 3. Target URL. The script i have written is entered into the Target URL. It works fine but i have to be on a certain page in the game to run the script because of how it gets the required info. At the minute i have two scripts doing what i would like one to do. The first script (that i wrote) and a second which just redirects me to the right page (which i have to click first). Can i get both tasks on to one script. What i would like the script to do is, upon clicking redirect me to the appropriate page the script needs to be run from, and then run the javascript function. My Script; ( which isnt finished but works fine for now) Code: JavaScript: var n = prompt("1.Plunder / Looting 2. OD 3.Archer 4.Axe ", "1");n = parseInt(n); if(n == 1) {var stringOne = (document.getElementsByTagName("img")[12].title);var stringTwo = (document.getElementsByTagName("img")[10].title);var stringThree = (document.getElementsByTagName("img")[25].title);var stringFour = (document.getElementsByTagName("img")[24].title);var stringFive = stringOne + " \n" + stringTwo + " \nToday " + stringThree + " \nToday " + stringFour + "";alert (stringFive );}; if(n == 2) {var stringSix = (document.getElementsByTagName("img")[15].title);var stringSeven = (document.getElementsByTagName("img")[22].title);var stringEight = (document.getElementsByTagName("img")[23].title);var stringNine = stringSix + " \nToday as attacker " + stringSeven + " \nToday as defender " + stringEight + "";alert (stringNine );}; To sum up. Basicly i want to be able to click the link to this script and have it redirect me to the right page and then run. So where would i put the page address and how do i make the script rum when the page is loaded. Thread duplicated see one above!
I finished this code, the full code is not here, but when I ran it as a diagnostic the action did not occur when i clicked on the "process item" button. I believe it may have something to do with the script, but i am new to javascript and cannot seem to figure it out, it is supposed to multiply the price by the number to give the value of sale (sale). Any help would be much appreciated!!! Code: <html> <script language="javascript"> function test() { var Items,Price,Number,sale; Items = parselfloat(document.victoria.secondnumber.value); Price = parselfloat(document.victoria.price.value); Number = parselfloat(document.victoria.num.value); sale = Price*Number; document.victoria.val.value=sale; } </script> <body><form name ="victoria"> <center> <table border=40 bordercolor="yellow"> <tr><td>Customer Number <input name ="firstnumber" type="text" size="6" value="1" ></td> <td>Home Delivery <input name="customer_name" type="checkbox"Checked></td><tr> <tr><td>Items Purchased</td><td><center><input name="secondnumber" type="text" size="12"></center></td></tr> <tr><td>Item Number</td><td><center><input name="itemnum" type="text" size="12" value="1"></center></td></tr> <tr><td>Price</td><td><center><input name="price" type="text" size="12"></center></td></tr> <tr><td>Number Purchased</td><td><center><input name="num" type="text" size="12"></center></td></tr> <tr><td>Value of Sale</td><td><center><input name="val" type="text" size="12" value="0"></center></td></tr> <tr><td>Customer Total</td><td><center><input name="total" type="text" size="12" value="0"></center></td></tr> <tr><td></td><td><input type="button" value="Process Item" onclick="test()"></td></tr> </table> </center></form> </body></html> |