JavaScript - How Do You Include An Outside File Into Script?
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! Similar TutorialsDoes anyone know how to accomplish this? I got the html file to show but none of the text in the file will show.
I included a js file into my html file. Everything work well in firefox but intenet explorer does not display my js file content. please helppp Js file // JavaScript Document document.write(<div class="RightSideGallerybox"> <div class="RightBoxContext">News</div> <div class="RightBoxPictures"><img src="../image/BotanicalTreeDecoration.jpg" /></div> <div class="RightBoxPictures"><img src="../image/IMG_3304.JPG" /></div> <div class="RightBoxPictures"><img src="../image/IMG_0297.JPG" width="150" height="100" /></div> <div class="ImportantRemarks">High School Admissions</div> <div class="ListOfRemarks"> <ul> <li>A. Phillip Randolph HS</li> <li>Astor Collegiate</li> <li>Aviation High School</li> <li>Bard College HS</li> <li>Bayside High School</li> </ul> </div> </div>); html file <div class="RightSideWrap"> <div class="footertext"> <script type="text/javascript" src="gallery.js"></script> </div> <!-------------------------------middle parts - right side--------------------------> </div> </div> Hi! how do I include .html files inside a document.write()? Like document.write('include top.html' "hello!" 'include bottom.html') or something. I searched for it, and found this: <!--#include file="top.html" --> But it doesn't work for me. What is wrong? I would be very happy if someone could help me 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 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. 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 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! 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}); 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! I have the following JavaScript (see below). The script requests an XML file from the server and displays it on the page. The script works fine when the requested XML file is stored on the same server as the script. The problem is when I try requesting an XML file from an external server such as the National Weather Service. I get an error. If I take the XML file from the National Weather Service and save it to my server it works. Why can't I use my script to request XML files stored on external servers? Thanks in advance for any help. Javascript Code Code: window.onload = initAll; var xhr = false; function initAll() { document.getElementById("makeTextRequest").onclick = getNewFile; document.getElementById("makeXMLRequest").onclick = getNewFile; } function getNewFile() { makeRequest(this.href); return false; } function makeRequest(url) { if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else { if (window.ActiveXObject) { try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } if (xhr) { xhr.onreadystatechange = showContents; xhr.open("GET", url, true); xhr.send(null); } else { document.getElementById("updateArea").innerHTML = "Sorry, but I couldn't create an XMLHttpRequest"; } } function showContents() { if (xhr.readyState == 4) { if (xhr.status == 200) { if (xhr.responseXML && xhr.responseXML.contentType=="text/xml") { var outMsg = xhr.responseXML.getElementsByTagName("choices")[0].textContent; } else { var outMsg = xhr.responseText; } } else { var outMsg = "There was a problem with the request " + xhr.status; } document.getElementById("updateArea").innerHTML = outMsg; } } HTML Code 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> <title>My First Ajax Script</title> <script type="text/javascript" src="script01.js"></script> </head> <body> <p><a id="makeXMLRequest" href="http://www.weather.gov/xml/current_obs/KOJC.xml">Request an XML file</a></p> <div id="updateArea"> </div> </body> </html> Hi guys, I've found tooltip I want to include in one of pages, and I'd appreciate your help. http://code.drewwilson.com/entry/tiptip-jquery-plugin I'm having troubles in finding a way to display it. Here is how I made it on this demo page : http://www.air.vlexo.net/tiptip/ I'm not sure what I did wrong, so please help me figure it out. Thanks in avance. I've now go to the point of wanting to include one javascript file within another. I was hoping for something analagous to: PHP Code: include("myfile.php"); But there isn't any built-in way of doing that?! I can see that it would be a security issue if you could include JS from anywhere - but surely it wouldn't be a problem if you could only include scripts on the same host as the including script? Hi I am in the middle of building some API's for my site and have built a cernal for all API's to read but i dont want the user to add two script tags to their sites code so I was wondering how I could do this. These are not my real files but will give you the full view of what it is I am trying to do. - cernal.js Code: var error = function(o) { if(o !== '') { alert(o); } }; - pub109283746374.js Code: // include the cernal.js file here somehow // Do a small function that uses the error cernal function function ShowNotice() { if(API_KEY !== '' && API_KEY !== undefined) { alert('Success'); } else { error('Sorry but you have an invalid API key.'); } } - http://www.userswebsite.com/demoFile.html 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> <title>WHOISearch API Demo</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="http://www.mysite.com/API/pub109283746374.js"></script> </head> <body> <script type="text/javascript"> //<![CDATA[ ShowNotice(); // Alerts 'Sorry but you have an invalid API key.' //]]> </script> <script type="text/javascript"> //<![CDATA[ API_KEY = 'pub109283746374'; ShowNotice(); // Alerts 'Success' //]]> </script> </body> </html> If anyone can help me it will help me so much with finishing these API's, please reply if you know how I can do this, Thank You. DJCMBear Greetings! I included this script in my php mysql query result. test.php Code: <html> <head> <title></title> <script type = 'text/javascript'> function addRow() { tabBody=document.getElementById("inputtable"); row=document.createElement("TR"); cell1 = document.createElement("TD"); cell2 = document.createElement("TD"); cell3 = document.createElement("TD"); cell4 = document.createElement("TD"); cell5 = document.createElement("TD"); cell6 = document.createElement("TD"); textnode1=document.createElement("input"); textnode1.name="accnum[]"; textnode1.type="text"; textnode2=document.createElement("input"); textnode2.name="copy[]"; textnode2.type="text"; textnode3=document.createElement("input"); textnode3.name="locate[]"; textnode3.type="text"; textnode4=document.createElement("input"); textnode4.name="funds[]"; textnode4.type="text"; textnode5=document.createElement("input"); textnode5.name="stat[]"; textnode5.type="text"; textnode6=document.createElement("input"); textnode6.name="remarks[]"; textnode6.type="text"; cell1.appendChild(textnode1); cell1.appendChild(textnode2); cell1.appendChild(textnode3); cell1.appendChild(textnode4); cell1.appendChild(textnode5); cell1.appendChild(textnode6); row.appendChild(cell1); row.appendChild(cell2); row.appendChild(cell3); row.appendChild(cell4); row.appendChild(cell5); row.appendChild(cell6); tabBody.appendChild(row); } </script> </head> <body> <form> <table> <tbody id="inputtable"> <tr><td> <input type = 'text' name = 'accnum[]' placeholder = 'Accession number' /> <input type = 'text' name = 'copy[]' placeholder = 'Copies' /> <input type = 'text' name = 'locate[]' placeholder = 'Book Location' /> <input type = 'text' name = 'funds[]' placeholder = 'Source fund' /> <input type = 'text' name = 'stat[]' placeholder = 'Status' /> <input type = 'text' name = 'remarks[]' placeholder = 'Remarks' /> </tbody> </table> <br/> <input type="button" value="Add new" onclick="addRow();" /></td></tr> <br/><br/> <input type = 'submit' name='submit' value = 'Submit'/> </form> </body> </html> PHP Code: $query2 = mysql_query("SELECT * FROM tbl_bacquisition WHERE bd_Id = '$bdID'") or die (mysql_error()); while ($row2 = mysql_fetch_assoc($query2)) { echo $row2['ba_Accnum'].' '.$row2['ba_Copynum'].' '.$row2['ba_Section'].' '.$row2['ba_Sfunds'].' '.$row2['ba_Status'].' '.$row2['ba_Remarks'].'<br/>'; } } echo '<br/>'; include 'test.php'; My problem is that my script is not performing its job, it adds row when the button is clicked. But when I tried to other page, it works. Any help would be so much appreciated. Hi all, I cant get this code to work because I do not know how to include the % character. Any help would be appreciated. My line break isnt working either Cheers, Adrian Code: rightButton.innerHTML = (rightOutcome1Prob+" chance of "+rightOutcome1+"\r\n else "+rightOutcome2); Ok I want to be able to include a html file into my template. I want the php include to work when I press a button that will put the include into a specific element with the document.getElementById("").innerHTML method in javascript. I want the include to be able to be more then a single line. For example I want to be able to write my code like this <div> some text </div> and not have to write it like this <div>some test</div> Thanks Shelby Hi all. The below script is from suckerfish. Can anyone help me include a 'one sec delay' to keep the menu open onmouseout. First menu often closes too fast before I get a chance to move onto submenu. I've tried everything with setTimeout BUT I just can't get it right. Nothing I do works. Can somebody PLEASE show me so I can kick myself. LT Code: <script type="text/javascript"><!--//--><![CDATA[//><!-- sfHover = function() { var sfEls = document.getElementById("nav").getElementsByTagName("LI"); for (var i=0; i<sfEls.length; i++) { sfEls[i].onmouseover=function() { this.className+=" sfhover"; } sfEls[i].onmouseout=function(){ this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); } } } if (window.attachEvent) window.attachEvent("onload", sfHover); //--><!]]></script> Is it possible to use Javascript to dynamically change the PHP file used for an include? For example, if I have a php doc like Code: <html> <body> <div>other stuff</div> <div> <?php include('onefile.php'); ?> </div> <div>more other stuff</div> </body> </html> I can get Javascript to remove the included stuff, but I can't figure out how to change the <?php include('onefile.php'); ?> into <?php include('otherfile.php'); ?>. What would be the best way to do that? So, I have a dynamic PHP file on my server. I want to make it so browsers can take the code I provide and paste it in an .html, .php, or .asp file, and it'll display across the board. The file would need to be included, unless someone thinks there's a better way of doing this? The only example I could think of would be Google Adsense's code? But I'm not sure. |