开发者

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.


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>


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.


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);


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?"


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜