Sohail
Sohail

Reputation: 548

How to disable a JavaScript hyperlink?

I just get a script from a website to put it on my own site, but it has a hyperlink on it and I want to disable that, here is the script:

<script language="javascript" src="http://www.parstools.net/calendar/?type=2"></script>

Thanks.

Upvotes: 2

Views: 3187

Answers (5)

hookedonwinter
hookedonwinter

Reputation: 12666

If the link is always going to be the same, and you know how to get that string into a variable, this should work:

str = str.replace( "<a href='http://www.ParsTools.com/'>", '' ).replace( '</a>', '' )

Edit in response to comment

This isn't best practice, but.. Wrap the js include in a div:

<span id="whatever">
    <script type="text/javascript" src="..."></script>
</span>

Then

<script type="text/javascript">
  str = document.getElementById( 'whatever' ).innerHTML
  str = str .... // what i said before
</script>

This solution doesn't require jQuery, which it looks like you don't want to use.

Upvotes: 1

Daniel Vassallo
Daniel Vassallo

Reputation: 344311

Following from your previous question, you may want to try the following:

<!DOCTYPE html>
<html> 
  <head> 
    <title>Simple Demo</title> 
  </head> 

  <script type="text/javascript">
     window.onload = function () {
       document.getElementById('calendar').innerHTML = 
          document.getElementById('calendar_hidden').getElementsByTagName('a')[0].innerHTML;
     };
  </script>

  <body> 

    <div id="calendar_hidden" style="display: none;">
       <script src="http://www.parstools.net/calendar/?type=2"></script>
    </div>    

    <div id="calendar" style="color: red;">       
    </div>

  </body> 
</html>

Upvotes: 2

Alastair Pitts
Alastair Pitts

Reputation: 19601

I had a look at the "script file" in question and i'm very confused.

This is the entire contents of the link: http://www.parstools.net/calendar/?type=2

document.write("<a href='http://www.ParsTools.com/'>1389/1/31</a>");            

It doesn't appear to be a calendar at all.

Can you provide more information regarding your using of this script file?

Upvotes: 0

Jake Wharton
Jake Wharton

Reputation: 76075

If you place that script inside of a <div id="something"> you can do the following:

var something = $('#something a');
something.replaceWith(something.contents());

assuming you include the jQuery library.

See "How to remove only the parent element and not its child elements in JavaScript?"

Upvotes: 0

EMP
EMP

Reputation: 61971

I presume you mean the script creates a new hyperlink element on the page. You could simply write your own JavaScript (after the external script), which disables it. With jQuery that would be something like

$('#hyperLinkId').attr('disabled', true);

Upvotes: 0

Related Questions