Jump to content

Bit of a Problem


Chocolate570

Recommended Posts

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:noiuqt.pngChocolate570and 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

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

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

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

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

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...