JavaScript - I Need An Alternative To Using <script Src For External Js Files
Hey guys.
So right now I'm able to execute javascript code on my website without the use of <script> tags. Example: <body onload=alert("cool");></body> What I want to be able to do is insert an external javascript file located at another website using JavaScript code (not script tags). How can this be done? Thanks Similar TutorialsHi everyone, I'm a newbie and this is probably really easy but it just won't work! I've tried looking at various online sources but they are all either too technical or don't seem to work. I'm obviously doing something wrong! The code is posted below, it's not very long so hopefully someone will be able to debug it! Thanks lots! Original page: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>variables</title> </head> <body> <script src="displaydate.js" type="text/javascript"></script> <br> </body> </html> External displaydate.js file: Code: function todaydate(){ var today_date= new Date() var myyear=today_date.getYear() var mymonth=today_date.getMonth()+1 var mytoday=today_date.getDate() document.write(myyear+"/"+mymonth+"/"+mytoday) } Opening the original page in my browser displays nothing. Just a blank page. Any help you can give would be greatly appreciated! Geoff I'm trying to program/modify a simple countdown timer in a .js file. I was able to get it to work when I just loaded the index.html file straight from my computer to my browser but it failed once uploaded. Here was the code for my index.html file. Code: <script type="text/javascript" src="countDown2.js"></script> <body> <b id='itgoeshere'>timer should go here</b> <script language ="Javascript"> window.onload = cd() </script> </body> and here is my code for my .js file Code: var days var hours var mins var secs; function cd() { var today = new Date() var eventDate = new Date(2012,0,28,19,19,70) difference = eventDate.getTime() - today.getTime() days = Math.floor(difference / (1000*60*60*24)) difference = difference - days * (1000*60*60*24) hours = Math.floor(difference / (1000*60*60)) difference = difference - hours * (1000*60*60) mins = Math.floor(difference / (1000*60)) difference = difference - mins * (1000*60) secs = Math.floor(difference / (1000)) redo(); } function dis(days,hours,mins,secs) { var disp; disp = days + ":" + hours + ":" + mins + ":" + secs; return(disp); } function redo() { secs--; if(secs == -1) { secs = 59; mins--; if (mins == -1) { mins = 59; hours--; if (hours == -1){ hours = 23; days--;}} } document.getElementById('itgoeshere').innerHTML = dis(days,hours,mins,secs); if((days == 0) && (hours == 0) && (mins == 0) && (secs == 0)) { window.alert("Chris is running."); // change timeout message as required } else { cd = setTimeout("redo()",1000); } } function init() { cd(); } window.onload = init; If I were to just cut and paste my .js code between my <script> it works but I was hopping to use it over again on multiple pages and having only one file to update. Also I'm very new at programming in general so if you see an obvious mistake not related to my question please let me know. I have an external Javascript file that only works when I put: Code: <script type="text/javascript" src="external.js"></script> at the end of the HTML page. Does anyone know why it won't work in the head of the page? Thanks Hi I need to develop a simple keyword search in external html files(having traversing in directories ability). Is this possible? (in this case php can be used) Please guide me Thanks If multiple pages reference the same external JS sheet, does the sheet reload every time you go to a new page or does it stay in memory?
What im trying to do is to dynamically call an external javascript file. The script once called will provide variables for another function. I have tried using this function PHP Code: function loadjscssfile(filename, filetype){ if (filetype=="js"){ //if filename is a external JavaScript file var fileref=document.createElement('script') fileref.setAttribute("type","text/javascript") fileref.setAttribute("src", filename) } else if (filetype=="css"){ //if filename is an external CSS file var fileref=document.createElement("link") fileref.setAttribute("rel", "stylesheet") fileref.setAttribute("type", "text/css") fileref.setAttribute("href", filename) } if (typeof fileref!="undefined") document.getElementsByTagName("head")[0].appendChild(fileref) } loadjscssfile("myscript.js", "js") //dynamically load and add this .js file loadjscssfile("javascript.php", "js") //dynamically load "javascript.php" as a J which works.The problem is that variables can not be passed through from the external script to the parent script. I understand why this is, but i am wondering if there are other ways to load (or refresh) an external script? I'm working on some code to create hover text that follows the mouse. Now, the code works fine when the javascript is included on the page: (internal script) http://cory.wellen.googlepages.com/hovertest2.html However, when I try to move the code out to an external script, it doesn't work. I've tried looking all over to see what the problem is, but 99% of those with external script problems have errors in syntax or location of the source script. Please help! (javascript) http://cory.wellen.googlepages.com/hover.js (external script) http://cory.wellen.googlepages.com/h..._external.html I have two pages one html page and one Javascript page index.html and script.js. I want to call the javascript page 3 times to display 3 images. How would I do this from my html page. script.js Code: <script language="JavaScript"> <!-- /* Random Image Link Script By Website Abstraction (http://www.wsabstract.com) and Java-scripts.net (http://www.java-scripts.net) */ function random_imglink(){ var myimages=new Array() //specify random images below. You can have as many as you wish myimages[1]="http://flashmajic.com/Google/atomica/atomicasmallicon.jpg" myimages[2]="http://flashmajic.com/Google/atomica/atomicasmallicon.jpg" myimages[3]="http://flashmajic.com/Google/atomica/atomicasmallicon.jpg" //specify corresponding links below var imagelinks=new Array() imagelinks[1]="http://www.wsabstract.com" imagelinks[2]="http://www.dynamicdrive.com" imagelinks[3]="http://www.java-scripts.net" var ry=Math.floor(Math.random()*myimages.length) if (ry==0) ry=1 document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=2 hspace=1></a>') } random_imglink() //--> </script> index.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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> ????? How would I call that script 3 times to display 3 random images? </body> </html> Hi I'm trying to load a part of a page (that has script in it) into another page using jquery. However, though the html loads in correctly, none of the script is working. I'm using code from http://css-tricks.com/video-screenca...namic-content/ ie. the pages all work without java (static pages) and when java is enabled, instead of going to bio.html you get taken to ..#bio.html. However if I've got any script I would like to be loaded .. ie. lightbox gallery or even a simple jav split and put back together email address hider. Any help greatly appreciated. I'm not very clued up about jquery at the moment unfortunately and though I've been trying to read and learn, alot is going over my head.. Not sure how best it is to show you the page as it's not live yet. Maybe if it helps I can upload a zip of the site. It's a simple 6 page musician site. Though my code is exactly like the css-tricks page, just that I have a lightbox on one page (which loads fine if there's no hash in the address - but when hash is there, it shows thumbnails, and when you click one, it just takes you to the larger .jpg destination page (no lightboxness etc).) Thanks I have the following code: Quote: <form id="registration" action="/cgi-bin/registration.cgi" method="POST" onsubmit="return control()"> <fieldset> <legend>Fill up this module</legend> Private <input id="private" type="radio" name="type" value="private" onclick="return addPrivate()"/><br/> Community/Organization <input id="organization" type="radio" name="type" onclick="alert('Organization')"/><br/> <br/> and the following script: Quote: addPrivate() { alert('Private'); } but alert windows doesn't not appear. Where is the problem? I built some pages that uses a Flash widget to play mp3 files on my server and show album covers at the same time. However, for people without Flash (like iPhone/Safari), I accommodate them by using a JavaScript that offers a list of simple links to the mp3 files. What I would really like, in the case of a page where there are several songs by the same artist, is a script that when activated, will play all the files in order. Possible? Where would I look for such a script?
The title says it all! any help would be appreciated... i have a script that will resize each image to various sizes and inserts them all into a database, the only problem is, SWFUpload isnt passing the file to the script, so its trying to process "nothing"
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 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, I hav linked external js (ext1.js) to my app.html page. Now in the ext1.js, I have a function like [CODE] function onwindowload(){ //Access HTML element and append external js 2 (ext2.js) here }[CODE] //Access HTML element and append external js 2 (ext2.js) here--->I donno how to add external JS here. Even if i add the external JS here, the JS uses document.write fn. which replaces entire page. Please suggest a solution is there any alternative to document.write() which writes only in a specific part of document, does not overwrite whole document. and yeah, in this case the document.getElementById().innerHTML dosent work either, coz its in a loop, here's the code if you wanna see: Code: if (aa==1) { for (i=0;i<a.length;i++) { c = txt; b = a[i].childNodes[0].nodeValue; // a is already assigned someplace in a xml document. txt = (b==" T4 ")? "T4 <br />": ""; document.write(c); } } Note: in the above code, the code: Code: txt = (b==" T4 ")? "T4 <br />": ""; is same as (also can be written as ) the code : Code: if (b==" T4 ") { txt = "T4 <br />" ; } else { txt = "" ; } I have this code http://www.jsfiddle.net/Nntc7/ created by a pdf publisher, I need to offer non flash content to users but dont know javascript and I cant get the thing to work using swfobject, How do I edit this to allow for alternative content?? thanks in advance The site i am building uses a large content slider as its main navigation. There is an absolutely positioned header on the page, and the slider sits underneath. This all works perfectly once i am linking (to named anchors) within the same page However when an external pages links to one of the anchors, the top of the slider content is hidden underneath the header - the user need to scroll down to get the content to start below the header. Long story short, I have used the following to force the browser to scroll to the top of the page when it loads: <script type="text/javascript"> window.onload = function(){ window.scrollTo(0,0); } </script> This doesnt load until everything else on the page has loaded though, is there a way to force the browser to scroll to the top BEFORE everything else loads? Or better yet not to scroll at all but to make sure the window is positioned at (0,0) automatically when it loads? Also, this doesnt seem to be working at all in IE Thanks in advance! Issue: I have a java script that bring up a simple password box, It works great in Chrome, Safari, firefox but I get a box in Internet explorer asking my customers to take another step to allow access. This is not good, Customers did not now what to do. Error: This website is using a scripted window to ask you for information. If you trust this website, click here to allow scripted windows Microsoft response: "Internet Explorer has blocked a website from using a small program (called a script) to display a separate window. Hackers sometimes use scripted windows to mimic legitimate windows, such as login screens, that appear on websites. If you trust the website and want to allow the scripted window, click the Information Bar, and then click Temporarily Allow Scripted Windows. To always allow scripted windows, check the Allow websites to prompt for information using scripted windows custom security setting." Objective: I now there is likely no way to by pass this, so i need a different solution. Possible a Form Box to be present on the site that when information is entered it passes the password to the javascript code to allow access? Please help, this is actually urgent as I have already lost a customer :-( Code: : <script> function getStyle() { var temp = document.getElementById("admintable").style.visibility; return temp; } function switchMain() { var isAuthed = authenticate(); if(isAuthed){ var current = getStyle(); if( current == "visible" ){ document.getElementById("admintable").style.visibility = "hidden"; }else{ document.getElementById("admintable").style.visibility = "visible"; } } } function authenticate() { if(readCookie('authenticated')!=null) { return true; } else{ var password=prompt("Enter Code","") if (password =="1234") { createCookie('authenticated',true); return true; } } return false; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } </script> Here is what I found online: http://www.anyexample.com/webdev/jav...lternative.xml UPDATE: I am a n00b, I need to incorporate this code below to the one above. Thanx Philip Code: <input type = "password" name = "pwd" id = "pwd" onchange = checkPassword(this.value)" <script type = "text/javascript"> function checkPassword(which) { if (which != "1234") { // password is visible!!! alert ("Incorrect password - please try again"); document.getElementById("pwd").value =""; return false; } else { alert ("Password is correct!"); //do more stuff here, e.g create the cookie } } </script> |