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.
5 Answers 5
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>
Comments
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.
5 Comments
span as well! (between the </script></div>, you need </span>)window.onload event, as in the example of my answer: stackoverflow.com/questions/2672421/…. Otherwise, the string replacement will happen before the external script is loaded.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);
1 Comment
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?"
4 Comments
<script> tag to the Google-hosted version (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.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?
src? That's how the script is loaded. What are you attempting to do by "disabling" it?