views:

190

answers:

5

Hi everyone, I just get a script from a website to put it on my own, 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"&gt;
   </script>

thanks.

A: 

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);
Evgeny
Thanks for your answer Evgeny, the script actually is a Calendar, and when I add this part to my page, it appears fine, but when you mouse over on it, it has a link to it's website (parsitools.net) and I want to disable that, and about jQuery, I really don't know anything about that and how I can add this to my page, I would really appreciate if you explain it much clearly for me, thanks
Sohail
A: 

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

Jake Wharton
I put a div behind my script like this: <div id="calendar"><script></script></div> and where I have to put your codes then ? sorry for being so unfamiliar with jQuery
Sohail
and also how can I add jQuery library to my page ?
Sohail
You can download it from their website (http://jquery.com) or link a `<script>` tag to the Google-hosted version (http://code.google.com/apis/ajaxlibs/documentation/index.html#jquery). Since the code is so simple inside of the remote script you might be better off with a pure JS solution similar to hookedonwinter.
Jake Wharton
Check out jquery.com. Tons of very awesome documentation.
hookedonwinter
+1  A: 

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/'&gt;", '' ).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.

hookedonwinter
yes the link is always going to be the same, but where I should add this: str = str.replace( "<a href='http://www.ParsTools.com/'>", '' ).replace( '</a>', '' )
Sohail
See edit in my answer
hookedonwinter
I've done this as far as I get you, see if I go wrong anywhere<div id="calendar"><span id="whatever"> <script language="javascript" src="http://www.parstools.net/calendar/?type=2"> </script> <script type="text/javascript"> str = document.getElementById( 'whatever' ).innerHTML() str = str.replace( "<a href='http://www.ParsTools.com/'>", '' ).replace( '</a>', '' )</script> </div>thanks.
Sohail
You don't need to put my script in the <div>, but it works as long as we're ignoring standards :) Don't forget to close the `span` as well! (between the </script></div>, you need </span>)
hookedonwinter
@user320946: I think you need to use the `window.onload` event, as in the example of my answer: http://stackoverflow.com/questions/2672421/how-to-disable-a-javascipt-hyperlink/2672508#2672508. Otherwise, the string replacement will happen before the external script is loaded.
Daniel Vassallo
Yes, do what Daniel says.
hookedonwinter
+1 for suggesting good practice :)
Daniel Vassallo
thanks every one, Daniel way works just fine, and one more thing, I cant vote up yet, as far as I dont have enough reputation
Sohail
A: 

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/'&gt;1389/1/31&lt;/a&gt;");            

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

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

Alastair Pitts
it's a calendar for some middle-east region actually
Sohail
A: 

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"&gt;&lt;/script&gt;
    </div>    

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

  </body> 
</html>
Daniel Vassallo
Thanks again for your helps, it does work fine too.
Sohail