We help IT Professionals succeed at work.
Get Started

Javascript remove <a> tag Firefox issue

lcor
lcor asked
on
665 Views
Last Modified: 2012-08-15
This is a followup to a question I asked.  Here's the question:
I have a javascript function for a printer friendly page.  The only problem is that hyperlinks show up in the printer friendly page.  I need the text within the <a> tags without the links.

How do I remove just the <a> tags from document object?  Please, no CSS -- I need to get the javascript below working.

Here's the javascript code:

var html = document.getElementById("spacer").innerHTML;
var winprint = window.open("", "", sOption);

winprint.document.write(html);


The answer was

winprint.document.write(html.replace(/<a[^>]*>(.*?)<\/a>/gi,'$1'));

I tried it on Internet Explorer and it works but does not work on Firefox 10.

Any ideas why and how to fix?
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015
Commented:
This problem has been solved!
Unlock 2 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE