How to disable JavaScript hyperlink?

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

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

      

Thanks.

+2


a source to share


5 answers


Following on from your previous question , you can try this:



<!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>

      

+2


a source


If the link will always 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

It's not 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 looks like something you don't want to use.

+1


a source


I assume you mean that the script creates a new hyperlink element on the page. You can just write your own JavaScript (after the external script) that will disable it. With jQuery, which would be something like

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

      

0


a source


If you put your script inside <div id="something">

, you can do the following:

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

      

if you include jQuery library.

See " How do I remove only a parent element and not its children in JavaScript? "

0


a source


I looked at the "script file" and I am very confused.

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

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

      

It is not a calendar at all.

Can you provide more information on using this script file?

0


a source







All Articles