The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
RegExp.replace Not Working
I'm using the following function to modify tags used for mouseover text:
Code:
function delHoverX() { re = /(\bdsc00001\b)/i; imgTags = document.getElementsByTagName("img"); for (i=0; i<imgTags.length; i++) { if (re.test(imgTags[i].title)) { origTitle = imgTags[i].title; origAlt = imgTags[i].alt; imgTags[i].title.replace(re, "$1"); imgTags[i].alt.replace(re, "$1"); if (origTitle == imgTags[i].title && origAlt == imgTags[i].alt) { imgTags[i].title = "same"; imgTags[i].alt = "same"; } } else { imgTags[i].title = ""; imgTags[i].alt = ""; } } } For some reason, the regexp.replace is not working. There is a test clause in there to help me diagnose some of what's going on. I'm not a Javascript programmer. I only have a limited background in C. I've been working on this for 2 days and am frustrated out of my mind. Any assistance appreciated. |
#2
|
|||
|
|||
If that is a vBulletin-powered page, it will be easier and cleaner to replace in the HTML output before it's even sent to the browser. Do this via a hook in global_complete (IIRC) on the $output variable.
|
#3
|
|||
|
|||
Unfortunately, this isn't a vb page. I don't have almost any control on anything. This was code that was given to me that should work and I've narrowed it down to one test case (dsc00001) just to get it working.
It seems like the .replace isn't working for some reason. In spite of the fact that the re.test works dropping it inside the if. I've looked at the RegExp documentation for Javascript on devguru as well as other sites. I've looked at examples. Seems like everything is written correctly, but it is still not working. I'm simply dumbfounded. If this was in C, I'd step through the whole thing line-by-line while watching every single variable. But I don't have any tools to do that here. Any ideas? |
#4
|
|||
|
|||
Turn on displaying all JavaScript errors in your browser. This might give you a clue.
|
#5
|
|||
|
|||
I will try that. Good idea!
Results--no errors related to that code. (There's one error that's there because of a call to a vb object leftover from a cut-and-paste of some vb generated html.) Any other ideas? I'm playing with using .match now with some better results, but still unusual things are happenning. |
#6
|
|||
|
|||
Are you trying to create a title attribute for each image that already has an alt tag?
|
#7
|
|||
|
|||
That's exactly what I was trying to do. I don't understand why I never got the email from vb.org of your response. Thank you for your help!
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|