Javascript Replace not working in IE (of course!)

  • dyfrin
  • Expert
  • Expert
  • User avatar
  • Posts: 503
  • Loc: WI

Post 3+ Months Ago

Hi guys.
Trying to get phpbb to create a link on their new "forum link" type of forum. Unfortunately you can't pass variables from php to the link.
To get around that, got this going:

Created a forum thats a link with http://changeme as the link

at the overall footer I threw in
Code: [ Select ]
<script type="text/javascript">
New = "<a href=\"http://domain.com/players.php?pid={S_PLAYER_ID}\" class=\"forumtitle\">Roster</a>"
a = document.getElementsByTagName("dt")
for (i=0; i<a.length; i++)
if((a[i].innerHTML.match("<a href=\"http://changeme\" class=\"forumtitle\">Roster</a>"))){a[i].innerHTML=a[i].innerHTML.replace("<a href=\"http://changeme\" class=\"forumtitle\">Roster</a>",New);
}
</script>
  1. <script type="text/javascript">
  2. New = "<a href=\"http://domain.com/players.php?pid={S_PLAYER_ID}\" class=\"forumtitle\">Roster</a>"
  3. a = document.getElementsByTagName("dt")
  4. for (i=0; i<a.length; i++)
  5. if((a[i].innerHTML.match("<a href=\"http://changeme\" class=\"forumtitle\">Roster</a>"))){a[i].innerHTML=a[i].innerHTML.replace("<a href=\"http://changeme\" class=\"forumtitle\">Roster</a>",New);
  6. }
  7. </script>


Works in Safari/FF but of course IE doesnt.
What is a good workaround or recoding to do here?

Thanks!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Zielak69
  • Novice
  • Novice
  • Zielak69
  • Posts: 21
  • Loc: Poland

Post 3+ Months Ago

I don't really know whats the problem. I barely know JS but:
Don't care about the IE, nobody smart uses it nowadays :)
Some things just don't work on there.
  • casablanca
  • Proficient
  • Proficient
  • User avatar
  • Posts: 481

Post 3+ Months Ago

Zielak69 wrote:
Don't care about the IE, nobody smart uses it nowadays :)

What makes you say that? See this: http://en.wikipedia.org/wiki/Usage_shar ... b_browsers
  • dyfrin
  • Expert
  • Expert
  • User avatar
  • Posts: 503
  • Loc: WI

Post 3+ Months Ago

Well I have been looking around at posts about replace not working in IE, so instead decided to find a different script:

programming-forum/search-replace-t40494.html

It appears to be working! A quick touch up will fix it all, thanks ozzu!
  • AdaWong
  • Born
  • Born
  • AdaWong
  • Posts: 1

Post 3+ Months Ago

Hello quick response as I just found out what was wrong with my code (had a similar problem with IE) instead of using the replace with text like you did use a regular expression

before I had this
Code: [ Select ]
.replace('<img src="images/correct.png" alt="valid" width="20px">', "");
but it wouldnt work on IE but then I changed it to
Code: [ Select ]
.replace(/^<.*">/g, "");

and it worked! just be sure to not use "" or '' around the regular expression!

Hope it helps :)

Ada J wong

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: Bigwebmaster and 96 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.