Chocolate570 Posted February 14, 2006 Share Posted February 14, 2006 K, I'm working on a script for forums.Basically, what this script does, is in specific places, it adds a picture of an envelope next to the link leading to the member profile. To get a better idea, go to this site:http://s15.invisisonfree.com/redifiedAs you can see, I've got the part where it goes next to the name down. What this script is supposed to do, is add the image next to the name---and then make the image lead to a function which extracts a specific part of the link to the player profile it's next to. Then, the envelope's link links to another part of the site, but with the variable i extracted used. For example, we have this picture:Chocolate570and the code is: <script type="text/javascript">function goThing(test){alert("If this script were the real version, it would take you to [url="http://s15.invisionfree.com/Redified/index.php?act=Msg&CODE=04&MID="+test+""]http://s15.invisionfree.com/Redified/index...ot;+test+"[/url]. But as it isn't, all you get is this alert box. ")/*window.location="http://s15.invisionfree.com/Redified/index.php?act=Msg&CODE=04&MID="+test*/}linkAr=document.links;reg=/showuser=/gfor(specLink=0;specLink<linkAr.length;specLink++) { if(linkAr[specLink].href.match(reg)) { prevIH=linkAr[specLink].parentNode.innerHTML; if(prevIH.match(/Log/g) || prevIH.match(/In/g) || linkAr[specLink].parentNode.className=="row2");else{/*c_start=prevIH.indexOf("showuser")if (c_start!=-1) { c_start=c_start + prevIH.length+1; c_end=prevIH.indexOf("=",c_start) if (c_end==-1) c_end=prevIH.length final=prevHI.substring(c_start,c_end); alert(final) } */linkAr[specLink].parentNode.innerHTML='<span style="cursor:pointer;cursor:hand" onclick="goThing(2)"><img src="http://i1.tinypic.com/noiuqt.png"></span>'+prevIH;} }}</script> Please don't hesitate to ask if you don't understand. I can hardly understand myself! ~Choco Link to comment Share on other sites More sharing options...
Chocolate570 Posted February 16, 2006 Author Share Posted February 16, 2006 Bumpity bump. Link to comment Share on other sites More sharing options...
scott100 Posted February 16, 2006 Share Posted February 16, 2006 wow that hurt my head <span onclick="goThing()"><img src="http://i1.tinypic.com/noiuqt.png"></img></span><a href="showuser=1">Chocolate570</a>Is this for this site, if so should it not be member Number? Link to comment Share on other sites More sharing options...
Chocolate570 Posted February 17, 2006 Author Share Posted February 17, 2006 Nope, but it is for a forum. It's not for this site in particular, however.Look, this is all i want to do.Suppose i gave a function this:"http://www.somesite.com/index.php?showuser=1"it should return"1"Get it? Link to comment Share on other sites More sharing options...
hacknsack Posted February 17, 2006 Share Posted February 17, 2006 How about splitting the string? Â <script type="text/javascript"> Â function parseStr(str){ Â var temp = str.split("="); Â alert(temp[1]); Â } Â parseStr('http://www.somesite.com/index.php?showuser=1'); Â </script> Would that work out for you? Link to comment Share on other sites More sharing options...
Chocolate570 Posted February 17, 2006 Author Share Posted February 17, 2006 Thanks so much, hacknsack! That works perfectly.But I have another problem. :)I have an HTML table---and in it, many links.I want to add that envelope before every link, but not group them together in the beginning...for example:Envelope Envelope Envelope Chocolate570, TestingPMSystem, HacknsackIt should have EnvelopeChocolate570,EnvelopeTestingPMSystem,EnvelopeHacknsackDo you understand what I mean? Link to comment Share on other sites More sharing options...
scott100 Posted February 17, 2006 Share Posted February 17, 2006 Does this help you any? <script> function parseStr(str){ var temp = str.split("="); alert(temp[1]); }document.write('<table border="1">')for(var i=0;i<10;i++){ Â document.write('<tr>'); Â document.write('<td><img src="http://i1.tinypic.com/noiuqt.png" /></tr>'); Â document.write('<td><a href="#" title="http://www.somesite.com/index.php?showuser='+i+'" onclick="parseStr(this.title);">Username'+i+'</a></tr>'); Â document.write('</tr>');}document.write('<table>')</script> Link to comment Share on other sites More sharing options...
Chocolate570 Posted February 17, 2006 Author Share Posted February 17, 2006 No, it really doesn't. The problem is, this is a ready made forum---and IFB, so you can't edit the HTML directly. All you can do is edit the board wrappers. Link to comment Share on other sites More sharing options...
hacknsack Posted February 18, 2006 Share Posted February 18, 2006 You're welcome. See if this will get you going, using insertBefore(): <html> <head> <title></title> <script type="text/javascript"> function editLinks(){ var re = /showuser=(\d+)/; var links = document.getElementsByTagName('a'); var img_src = "http://www.google.com/images/firefox/light.gif"; for(var j = 0; j < links.length; j++){ if(links[j].href.match(re)){ if(navigator.userAgent.indexOf('MSIE') > -1 && navigator.userAgent.indexOf('Opera') == -1){ var nwImg = document.createElement('<img src="' + img_src +'" onclick="alert(' + RegExp.$1 +')">'); } else { var nwImg = document.createElement('img'); nwImg.setAttribute('src', img_src); nwImg.setAttribute('onclick', "alert('" + RegExp.$1 + "')"); } oParent = links[j].parentNode; oParent.insertBefore(nwImg, links[j]); } } } window.onload = editLinks; </script> </head> <body> <table> <tr> <td> <a href="http://s15.invisionfree.com/Redified/index.php?showuser=2">User 2</a> <a href="http://s15.invisionfree.com/Redified/index.php?showuser=24">User 24</a> </td> <td> <a href="http://s15.invisionfree.com/Redified/index.php?showuser=13579">User 13579</a> </td> </tr> </table> </body></html> Shout back if it needs adjustments. Link to comment Share on other sites More sharing options...
Chocolate570 Posted February 20, 2006 Author Share Posted February 20, 2006 Thanks hacknsack! That seems to be exactly what I need. I'll tweak around with it and tell you if it works. Link to comment Share on other sites More sharing options...
Chocolate570 Posted February 21, 2006 Author Share Posted February 21, 2006 Why won't my code work in IE? <script type="text/javascript">///////////////////////////////////////////////        |EnvelopeMod|         ////           ~v1~            ////     ©2006 Chocolate570       //  //     Fiddling with this code      ////  Could cause execution failiure   ////  Translation: The thing'll blow up  ////www.Seekond.com --- www.IFSZ.net ////////////////////////////////////////////////Function that takes user to correct URLfunction compArg(usr){window.location="./index.php?act=Msg&CODE=4&MID="+usr}linkAr=document.links;reg=/showuser=(\d+)/g//Going through all the linksfor(specLink=0;specLink<linkAr.length;specLink++){//If it's found a link to a user profileif(linkAr[specLink].href.match(reg)){prevIH=linkAr[specLink].parentNode.innerHTML;//If the link is located in a place where an image shouldn't appearif(prevIH.match(/Log/g) || prevIH.match(/In/g) ||   linkAr[specLink].parentNode.className=="row2");else{parent=linkAr[specLink].parentNode//Checking browser---cross-browser issuesif(navigator.userAgent.indexOf('MSIE') > -1 && navigator.userAgent.indexOf('Opera') == -1){var newEnv = document.createElement('<img  src="http://i1.tinypic.com/noiuqt.png" onclick="compArg(' + RegExp.$1 +')">');}else{newEnv=document.createElement("img");newEnv.setAttribute('src','http://i1.tinypic.com/noiuqt.png');newEnv.setAttribute('onclick', "compArg('" + RegExp.$1 + "')");}//Add envelope picture next to current linkparent.insertBefore(newEnv,linkAr[specLink])}}}</script> :S Link to comment Share on other sites More sharing options...
hacknsack Posted February 21, 2006 Share Posted February 21, 2006 IE doesn't like the use of "parent" changed it and used {} after your "if". function compArg(usr){window.location="./index.php?act=Msg&CODE=4&MID="+usr}linkAr=document.links;reg=/showuser=(\d+)/g//Going through all the linksfor(specLink=0;specLink<linkAr.length;specLink++){//If it's found a link to a user profileif(linkAr[specLink].href.match(reg)){prevIH=linkAr[specLink].parentNode.innerHTML;//If the link is located in a place where an image shouldn't appearif(prevIH.match(/Log/g) || prevIH.match(/In/g) || linkAr[specLink].parentNode.className=="row2"){}else{oparent=linkAr[specLink].parentNode//Checking browser---cross-browser issuesif(navigator.userAgent.indexOf('MSIE') > -1 && navigator.userAgent.indexOf('Opera') == -1){var newEnv = document.createElement('<img src="http://i1.tinypic.com/noiuqt.png" onclick="compArg(' + RegExp.$1 +')">');}else{newEnv=document.createElement("img");newEnv.setAttribute('src','http://i1.tinypic.com/noiuqt.png');newEnv.setAttribute('onclick', "compArg('" + RegExp.$1 + "')");}//Add envelope picture next to current linkoparent.insertBefore(newEnv,linkAr[specLink])}}} Link to comment Share on other sites More sharing options...
Chocolate570 Posted February 21, 2006 Author Share Posted February 21, 2006 Hacknsack, it's official. You are the master of javascript. :)Thanks so much. It worked like a charm! Link to comment Share on other sites More sharing options...
hacknsack Posted February 21, 2006 Share Posted February 21, 2006 And you said Elvis is living where .. .. Glad it worked for you. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now