JavaScript - Please Can Someone Advise What This Script Might Do ?
I have been given files for my site and would like to know what the following script does or could do ?
Code: function parseScript(_source) { var source = _source; var scripts = new Array(); // Strip out tags while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) { var s = source.indexOf("<script"); var s_e = source.indexOf(">", s); var e = source.indexOf("</script", s); var e_e = source.indexOf(">", e); // Add to scripts array scripts.push(source.substring(s_e+1, e)); // Strip from source source = source.substring(0, s) + source.substring(e_e+1); } // Loop through every script collected and eval it for(var i=0; i<scripts.length; i++) { try { eval(scripts[i]); } catch(ex) { window.execScript(scripts[i]); } } return source; } this is one of the calls to this script I found in the other site files. Code: document.getElementById(element).innerHTML=parseScript(xmlhttp.responseText); is there a possible security risk on this ? any help on this is grately appreciated. Similar TutorialsHi all, The following code is an assigment.I have it running with out any errors.It has to take the array (arrayToshuffle) and through running though the end of the (arrayToshuffle) the string has to be shuffled.We havent learnmt shuffle() yet.) I think the problem is these lines. arrayToShuffle[index]=arrayToShuffle[swapIndex]; arrayToShuffle[swapIndex]=arrayToShuffle[index]; But no matter what varibles I put in these lines and how much i fiddle I carnt seem to get it to run without repeating the same elements in the output. I dont want anyone to fix it for me just advise on where I could look for problems. Am i missing somthing here? Heres the program if you run it you will see what I mean. <html> <head> <script> var arrayToShuffle = new Array('Ace','2','3','4','5','6','7','8','9','10','Jack','Queen','King'); var arraySize = arrayToShuffle.length; document.write('<h1>Array shuffling</h1>'); document.write('<p>Before shuffle: '+arrayToShuffle+'</p>'); SWAPS_TO_MAKE = 30; var index=0; var self_swaps=0; var counter = 0; while(counter < SWAPS_TO_MAKE) { var swapIndex = Math.floor(Math.random()*arraySize+1); arrayToShuffle[index]=arrayToShuffle[swapIndex]; arrayToShuffle[swapIndex]=arrayToShuffle[index]; if(index =swapIndex) { self_swaps++; } counter++; index = (index+1 % arraySize); } document.write('<p>After shuffle: '+arrayToShuffle+'</p>'); document.write('<ul>'); document.write('<li>Swaps made: '+SWAPS_TO_MAKE+'</li>'); document.write('<li>Self swaps: '+self_swaps+'</li>'); document.write('<li>Effective swaps: '+(SWAPS_TO_MAKE-self_swaps)+'</li>'); document.write('<li>Effective rate: '+((SWAPS_TO_MAKE-self_swaps)/SWAPS_TO_MAKE)+'</li>'); document.write('</ul>'); </script> </head> <body> </body> </html> Thanks heaps Shayne Darcy Hi, I am having a slight difficulty and hope someone can easily set me straight. I am trying to use the following code to track a button click and the second onclick event, the urchin tracking is not being completed but the first function is.... can someone please hopefully set me straight easily on the code? Many thanks Steve123. Code: <input type="submit" name="Submit" value="Buy Product" class="buy" onClick="document.form.submit();javascript:urchinTracker('/html/productdeals_button.asp')"> Hello, Iam currently experimenting with Java Scripting and have hit a wall about the use of Functions. I am trying to create a difference function which would work out the difference between two numbers. e.g. 14 and 18 I am able to create a function and if statement to find the larger number of a argument but am having trouble writing one to find the difference between two numbers. Iam also confused (i know probably a silly question) but is the operator used the same for this function. Hope people can make sense of that. Thanks, Hi all, I have just stated university a few weeks ago and have never programmed before.I am really stuck on this assigment .In the programm you have to enter you date of birth throught prompt (22).then your year of birth (yyyy),then your month (nov). I am really stuck and have been for days in requards how to put the information gained through prompt function into a date object().So i can get the users day of birth .Heres the code i have written .the varibles num5+num9+num1 is the users input but i just dont know how to assign it to the date object I have tryed heaps of ways but carnt get any thing to work .Please Help. head> <script> var tit1=('<title> Get your Stats </title>'); var tit2=('<h1> IT\'s about time...</h1><br /> ') var num1 =(''); num1=prompt('Enter The Year You Were Born','19XX'); var currentTime = new Date() var year = currentTime.getFullYear() var ansVar = year-num1; //User input year calculation var ageEx = (ansVar/62.7)*100; // Life% calculation var num2=ansVar var num3= ansVar*365.2424; // Days calcuation var month =('janfebmaraprmayjunjulaugsepoctnovdec'); var num5 =(''); num5=prompt('Enter The Month You Where Born','jan'); num5=(num5.substring(0,3)); var lowCas=(num5.toLowerCase());//users input conmverted to lower case/ var num9=prompt ('Enter you date of birth','29'); var d = new Date (num5+num9+num1)//<<<<this random date entered here will give the day. alert (d); //STUCK HERE HOW DO I CONVERT num5+num9+num1 to a day????????:: document.write(tit1); //output document.write(tit2); document.write(('You have lived ')+ageEx.toFixed(0)+('% of your life.<br />')); document.write(('You are ')+ansVar+(' years old.<br />')); document.write (('You are ')+num3.toFixed(0)+(' days old.')); </script> </head> </html> Any advise would be appreciated thanks Shayne darcy. Hi guys, Just a simple question, Since we can't delete object created with document.createElement(), and just let javascript internal garbage collection do the work. I would much appreciate if anybody would advise me, whether we should nullify the object first, for complete deletion by this collector? Thanks for reading, and advising... Hendra. Hi there I've just completed a lovely slideshow script on my homepage. It works great in Firefox, but doesn't display at all in IE. It's on a live test page he http://www.modern-wedding-ideas.co.uk/index2.html I'm sure I'm just missing something really simple. Any help would be greatly appreciated. Also, this is a copy and paste job: I'm a newbie to javascript! So please be gentle. Many thanks Nicola I have a page that takes nodes from drupal and pulls the athletes information and renders it into a roster page via a PHP array. initially the page did not have a logical sort and basically was rendered in the order of the node creation. I added sorttable.js to the file and you could then sort based on the header. However, our head coach wanted it to be sorted onLoad by player number (first column) so I added datatable and set aasorting to 0, asc and it actually sorts the second column (name) instead of column 1. No matter which column I set it to it only sorts the name column. If I could get some advice about how to fix this I would appreciate it. Code: <style type="text/css">table.sortable th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sorttable_nosort):after { content: " \25B4\25BE" } </style> <script src="/jscript/sorttable.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#roster').dataTable( { "aaSorting": [[ 0, "asc" ]] } ); } );</script> <table width="100%" cellpadding="2" cellspacing="2" border="1" class="sortable" id="roster" style="border-bottom:1"> <thead> <tr> <?php if( ! empty($vars['sport']->field_sport_show_number) && 1 == $vars['sport']->field_sport_show_number['und'][0]['value'] ): ?> <th class="style4, sortBy" style="width: 14px;" data-sortType="numeric" id="number"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">#</span></th> <?php endif; ?> <th class="style4" style="width: 14px;" ><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Name</span></th> <?php if( ! empty($vars['sport']->field_show_class) && 1 == $vars['sport']->field_show_class['und'][0]['value'] ): ?> <th class="style4" style="width: 14px;"><span style="font-family: Arial, Helvetic Hi All, I have two scripts which I want to try and integrate. I am using a nice gallery script to show thumbnails which are appended to a an image wrapper which on click of the thumbnail shows the larger image in the image wrapper, I am trying to implement cloud zoom which is a plugin which uses image srcs to then point to an anchor href to show another larger zoom image either in the same place.. which is what I am trying to do or in another div beside. I have had to set me img srcs up in a certain way to easily enter some product details. and I need to try an manipulate the code to make it work to suit my file layout. I am using a var= images [ with a series of file locations and info such as below { src: 'romanticabride/thumbs/tn_Shauna.jpg', srcBig: 'romanticabride/images/Shauna.jpg', title: 'Shauna', longDescription: '<b><H1>Shauna</H1></b><br><b>Romantica Of Devon <br><br><h2>Sizes Available:</h2><br> 6 - 32.<b><br><b><br><b><b><b><H2>Colours Available:</h2><b><br>Various<br>Please Enquire Below<br><br><br><br><a href="mailto:tracy@cherishbridal.co.uk?subject=Web Enquiry Regarding Romantica Shauna Bridal Gown"class="enquiry rose glow" >Click To Enquire About This Item </a>' }, what I need is for cloud zoom to work when the main image wrapper is hovered over which means it will need to add a class or when the whichever srcBig: is hovered over it gets wrapped by href to make the script work . one of my pages is http://www.cherishbridal.co.uk/romaticabride.html the cloud zoom script is at http://www.professorcloud.com/mainsite/cloud-zoom.htm.. I am happy to share a jsfiddle with someone or explain further or post some code. Thank you in advance does any expert know how to pass parameters in the <script ..> tag? for instance; Code: <script type="text/javascript" src="script.js ?param1=val1¶m2=val2&etc "> in the javascript script.js, how would we read the params after the question mark? for example, google this; google shopping cart /v2_2/cart.js I have a script that works in seamonkey(my html editor) but when I use it in IE8 it says errors happen. Here's the code (the first line is on line 7 of the html file): Code: <script type="text/javascript"> function enlarge(imageNum) { var numToString = ""; if(parseInt(imageNum) < 10){ numToString = "0" + imageNum; } else { numToString = imageNum + ""; } window.open("images/LgScreenshot"+numToString+".jpg","Screenshot "+imageNum,"status=0,height=675,width=900,resizable=0"); } </script> And the errors: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; GTB0.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; InfoPath.3; .NET CLR 3.0.30729) Timestamp: Wed, 10 Feb 2010 14:58:16 UTC Message: Object expected Line: 150 Char: 1 Code: 0 URI: http://samssc2site.co.cc/Features.html Message: Invalid argument. Line: 18 Char: 1 Code: 0 URI: http://samssc2site.co.cc/Features.html I need to assign a key in the javascript to actually make the javascript work,. I have a bookmark in chrome , a javascript , which actually works when clicked on it .,. but how can i edit it so that i can actually make it work on click a key or combination of keys. i want to declare the key or keycombo in the script itself .,. the script is for catching the selected text on the webpage and opening a new tab(or window) and doing an exact search search of the selected text using google.com .,., So I want it to work it this way ., select the text press a key and it opens a new tab (or window) with an xact search .,. i want to declare the key or keycombo in the script itself .,. the script is for catching the selected text on the webpage and opening a new tab(or window) and doing an exact search search of the selected text using google.com .,., So I want it to work it this way ., select the text press a key and it opens a new tab (or window) with an xact search .,. Thanks in advance ., Nani On this website: http://evancoleman.net/index.php I really like on the top how the menu has like 5 or 6 icons, and when you hover over them it shows a bubble with the name in them. Does anybody know where I can find this script? Thanks. Hello again . If these questions concerning Regular Expressions are inappropriate in this forum please let me know . Thank You. This expression <script[^>]*>.*?</script> matches ... Code: <script type="text/javascript">var cnnIsHomePage = true;</script> but not ... Code: <script type="text/javascript"> var cnnIsHomePage = true; </script> Please , how can i match the latter ? HI - I'm creating a golf website and the clients asked to put a "Golf Tip" on the site that could be changed. A Google search led me to your script (copied below) for "Tip of the Day", which seems to be exactly -- almost -- what I need. Can you tell me how to change the font color (for the tips) from gray to White? Also, is it possible to alter the script to make the tips weekly rather than daily? Thanks much, Richard Code: <table border="0" width="100%" bgcolor="#E8E8E8" cellspacing="0" cellpadding="0"> <tr><td width="100%"> <script> <!-- /* Tip of the day script By JavaScript Kit (http://javascriptkit.com) Over 200+ free scripts here! */ var today_obj=new Date() var today_date=today_obj.getDate() var tips=new Array() //Configure the below variable to contain the "header" of the tip var tiptitle='<img src="../../tip.gif"> <b>JavaScript Tip of the day</b><br />' //Configure the below array to hold the 31 possible tips of the month tips[1]='Tip 1 goes here' tips[2]='Tip 2 goes here' tips[3]='Tip 3 goes here' tips[4]='Tip 4 goes here' tips[5]='Tip 5 goes here' tips[6]='Tip 6 goes here' tips[7]='Tip 7 goes here' tips[8]='Tip 8 goes here' tips[9]='Tip 9 goes here' tips[10]='Tip 10 goes here' tips[11]='Tip 11 goes here' tips[12]='Tip 12 goes here' tips[13]='Tip 13 goes here' tips[14]='Tip 14 goes here' tips[15]='Tip 15 goes here' tips[16]='Tip 16 goes here' tips[17]='Tip 17 goes here' tips[18]='Tip 18 goes here' tips[19]='Tip 19 goes here' tips[20]='Tip 20 goes here' tips[21]='Tip 21 goes here' tips[22]='Tip 22 goes here' tips[23]='Tip 23 goes here' tips[24]='Tip 24 goes here' tips[25]='Tip 25 goes here' tips[26]='Tip 26 goes here' tips[27]='Tip 27 goes here' tips[28]='Tip 28 goes here' tips[29]='Tip 29 goes here' tips[30]='Tip 30 goes here' tips[31]='Tip 31 goes here' document.write(tiptitle) document.write(tips[today_date]) //--> </script> </td></tr></table> <p align="center"><font face="arial" size="-2">This free script provided by</font><br> <font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript Kit</a></font></p> Hi I have found a script I would like to make a few changes to.. I have tried a few tricks but got me no-where. If you could help me I will be very much appreciated! Code: <HEAD> <script language="javascript"> <!-- //These are the names of the people you don't want //To add a person, just put their name in quotation marks //and add a comma after Names = new Array( "test1@email.com", "test2@email.com", "test3@email.com", "test4@email.com", "test5@email.com") function Check() { //Change FORM and FIELD to the form name and field name throughout this function namechk=document.FORM.FIELD.value.toLowerCase() awdrgy = 0 aLeRt = 0 while (awdrgy<=Names.length-1 && aLeRt!=1) { if (namechk==Names[awdrgy]) { aLeRt = 1 alert("Either your account is suspended or you entered an invalid email address! Please try again.") document.FORM.FIELD.value="" } awdrgy++ } } --> </script> </HEAD> <BODY> <form name="FORM"> <input name="FIELD" onblur="Check();" onblur> <input type="button" onclick=storytest() value="Submit" class="form"> </form> <!-- Script Size: 2.01 KB --> Basically What I want to happen is.. If a email entered that is listed in the reject list they will get an alert. (This currently does this) If a email was entered that's not listed it will submit the form. (Currently does not do this) I am making a login form that is complete but I wanted to add the above code to it.. If you or anyone could make it work the way I explained above I will be very much appreciated. Thanks, Chris Hello this small clickunder script open windows behind current windows but it has problems that i want to be fixed : 1-This opens windows behind current windows when visitor clicks everywhere on the page . I need it works when visitors click only on links not everywhere on the page 2-i need it works for links with speacial id's , not every links Code: <SCRIPT LANGUAGE="Javascript"> function PopShow3() { CookieTest=navigator.cookieEnabled; if(CookieTest) { ClickUndercookie = GetCookie('clickunder'); if (ClickUndercookie == null) { var ExpDate = new Date (); ExpDate.setTime(ExpDate.getTime() + (1 * 60 * 60 * 1000)); SetCookie('clickunder','1',ExpDate, "/"); window.open("galst2.htm"); window.focus(); } } } function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) return getCookieVal (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } function SetCookie (name, value) { var argv = SetCookie.arguments; var argc = SetCookie.arguments.length; var expires = (argc > 2) ? argv[2] : null; var path = (argc > 3) ? argv[3] : null; var domain = (argc > 4) ? argv[4] : null; var secure = (argc > 5) ? argv[5] : false; document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : ""); } document.onmouseup=PopShow3; </SCRIPT> Hi everyone, I just wrote a little noob script and JSL tester says no errors but I think there's some kind of problem.....can you help me fix the problem???? Code: function doattack(baseatk, wepatk, wepcritmax, oppdef, oppdeffactor, oppextradefmax, opphealth, oppname) { var OpponentHealth = opphealth; var OpponentName = oppname; var BaseATK = baseatk; var WeaponATK = wepatk; var WeaponCriticalMax = "100+Math.floor(Math.random()*wepcritmax+1)"; var ActualWeaponATK = "WeaponATK * WeaponCriticalMax / 100"; var OpponentDEF = oppdef; var DEFfactor = oppdeffactor; //defensefactor: used to multiply preoppdef to calculate actualoppdef so more in number the better rmbr that deffactor must be less than 1 var DEFCriticalMax = "100+Math.floor(Math.random()*oppextradefmax+1)"; var PreOpponentDEF = "OpponentDEF * DEFCriticalMax / 100"; var ActualOpponentDEF = "PreOpponentDEF * DEFfactor"; var DamageDone = "BaseATK + ActualWeaponATK"; var OVRDamageDone = "DamageDone * ActualOpponentDEF / 100"; document.write("You just inflicted " + OVRDamageDone + " damage to " + OpponentName + "!" + "<br>"); var NewOpponentHealth = "OpponentHealth - OVRDamageDone"; if (NewOpponentHealth < 0) { document.write(OpponentName + " is dead!" + "<br>"); break; } else { doattack(BaseATK, WeaponATK, WeaponCriticalMax, OpponentDEF, DEFfactor, DEFCriticalMax, NewOpponentHealth, OpponentName); } } doattack(5, 50, 25, 6, 0.22, 10, 200, RedBabyDragon); GREAT THANKS Hi there, I'm not too familiar with js, so I'm asking for help I have this script below which loads flash object after clicking fb like button. My question is how to do it after clicking the fb like button automatically to recognize youtube flash object or an object from another tube site? Is it possible? Thank you in advance! Code: <script type='text/javascript'> window.fbAsyncInit = function() { FB.init({appId: "0000000000000", status: true, cookie: true, xfbml: true}); }; (function() { var e = document.createElement("script"); e.async = true; e.src = document.location.protocol + "//connect.facebook.net/en_US/all.js"; document.getElementById("fb-root").appendChild(e); }()); FB.Event.subscribe('edge.create', function(href, widget) { setTimeout("playvideo1();", 0); }); function playvideo1() { document.getElementById('playvideo1').innerHTML = '<object ....... </object>'; } </script> Hello all. I have a pretty important question. I am building a webapp for the iPad and I need to be able to drag divs around the page for it to work. I had this script which works in desktop browsers: Code: function Browser() { var ua, s, i; this.isIE = false; this.isNS = false; this.version = null; ua = navigator.userAgent; s = "MSIE"; if ((i = ua.indexOf(s)) >= 0) { this.isIE = true; this.version = parseFloat(ua.substr(i + s.length)); return; } s = "Netscape6/"; if ((i = ua.indexOf(s)) >= 0) { this.isNS = true; this.version = parseFloat(ua.substr(i + s.length)); return; } // Treat any other "Gecko" browser as NS 6.1. s = "Gecko"; if ((i = ua.indexOf(s)) >= 0) { this.isNS = true; this.version = 6.1; return; } } var browser = new Browser(); // Global object to hold drag information. var dragObj = new Object(); dragObj.zIndex = 0; function dragStart(event, id) { var el; var x, y; // If an element id was given, find it. Otherwise use the element being // clicked on. if (id) dragObj.elNode = document.getElementById(id); else { if (browser.isIE) dragObj.elNode = window.event.srcElement; if (browser.isNS) dragObj.elNode = event.target; // If this is a text node, use its parent element. if (dragObj.elNode.nodeType == 3) dragObj.elNode = dragObj.elNode.parentNode; } // Get cursor position with respect to the page. if (browser.isIE) { x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop; } if (browser.isNS) { x = event.clientX + window.scrollX; y = event.clientY + window.scrollY; } // Save starting positions of cursor and element. dragObj.cursorStartX = x; dragObj.cursorStartY = y; dragObj.elStartLeft = parseInt(dragObj.elNode.style.left, 10); dragObj.elStartTop = parseInt(dragObj.elNode.style.top, 10); if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0; if (isNaN(dragObj.elStartTop)) dragObj.elStartTop = 0; // Update element's z-index. dragObj.elNode.style.zIndex = ++dragObj.zIndex; // Capture mousemove and mouseup events on the page. if (browser.isIE) { document.attachEvent("onmousemove", dragGo); document.attachEvent("onmouseup", dragStop); window.event.cancelBubble = true; window.event.returnValue = false; } if (browser.isNS) { document.addEventListener("mousemove", dragGo, true); document.addEventListener("mouseup", dragStop, true); event.preventDefault(); } } function dragGo(event) { var x, y; // Get cursor position with respect to the page. if (browser.isIE) { x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop; } if (browser.isNS) { x = event.clientX + window.scrollX; y = event.clientY + window.scrollY; } // Move drag element by the same amount the cursor has moved. dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px"; dragObj.elNode.style.top = (dragObj.elStartTop + y - dragObj.cursorStartY) + "px"; if (browser.isIE) { window.event.cancelBubble = true; window.event.returnValue = false; } if (browser.isNS) event.preventDefault(); } function dragStop(event) { // Stop capturing mousemove and mouseup events. if (browser.isIE) { document.detachEvent("onmousemove", dragGo); document.detachEvent("onmouseup", dragStop); } if (browser.isNS) { document.removeEventListener("mousemove", dragGo, true); document.removeEventListener("mouseup", dragStop, true); } } And then I put this into the body section of the page: Code: <div id="boxA" class="box" style="left:400px;top:150px;"> <div class="bar" style="width:12em;" onmousedown="dragStart(event, 'boxA')">Drag Box B</div> <div class="content" style="width:12em;"> Enter stuff to be dragged here. </div> </div> The iPad doesn't read "onmousedown" correctly though, so I need another attribute to be put there instead. I tried "onclick" and then viewed it on the iPad and I was able to click on the div, then click around the page and the div would move there. If I use "onclick" though, something has to tell the browser that once I've clicked it once it stops moving if I click somewhere on the page. Like I said, if you can help, great! Hi everyone: I need help taking this pop under script: <script language="JavaScript"> var popunder="URL GOES HERE" function loadpopunder(){ win2=window.open(popunder) win2.blur() window.focus() } loadpopunder() </script> and making it so that I can set it so it only pops up one time and then will not pop up again until after a certain time period. Also, is there a way to make it so it can avoid pop up blockers? Thank you! |