disable js with js

C

chandy

Circular nonsense here but something says to me that it might just be
possible to at least emulate it. Does anyone know of a way to
effectively kill all JavaScript functions by using JavaScript iteself?

All CSS and browsing functionality would need to remain.

Chandy
 
M

Martin Honnen

Circular nonsense here but something says to me that it might just be
possible to at least emulate it. Does anyone know of a way to
effectively kill all JavaScript functions by using JavaScript iteself?

Well if your script has the rights to do so then with Netscape/Mozilla
calling
navigator.preference('javascript.enabled', false)
disables script. Only script in a HTML document loaded from a HTTP
server does not have the privilege to do so. And script in a HTML
document loaded from the local file system needs to request the
privilege. Script in an extension has the privilege to do such things.
 
J

jeffrey.bigham

I guess it depends on how loosely you want to define "CSS and browsing"
functionality.

If you don't care if you get rid of javascript enhanced CSS and
browsing functionality, then the following will probably work, although
it's untested and likely not to be completely robust:

First, get all the <script> elements from the page's DOM and remove
them - set there innerHTML to "" and remove their src attributes. Then
go through every other element and remove any event elements (onClick,
onKeyPress, etc.) contained within. Magically all of your javascript
disappears...ideally...

This worked for me...I think.

<html>
<script>
function traverseDomTree() {
var html_element = document.getElementsByTagName("html").item(0);
traverseDomTree_recurse(html_element);
alert("done");
}

function traverseDomTree_recurse(curr_element) {
var my_string = "";

if(curr_element == null) {
return;
}

if(curr_element.nodeName == "SCRIPT") {
curr_element.setAttribute("src", "");
curr_element.innerHTML = "";
return;
} else if(curr_element.nodeName == "#text") {
return;
}

curr_element.setAttribute('onclick', '');

var i;
for(i=0; curr_element.childNodes.item(i); i++) {
traverseDomTree_recurse(curr_element.childNodes.item(i));
}
}

</script>
<body>

<a href="#" onClick="alert('hello');">Click Here</a>

<br>

<input type="button" onClick="traverseDomTree();">

</body>
</html>

-Jeff
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Fri, 7 Apr 2006 08:54:50 remote, seen in
Circular nonsense here but something says to me that it might just be
possible to at least emulate it. Does anyone know of a way to
effectively kill all JavaScript functions by using JavaScript iteself?

All CSS and browsing functionality would need to remain.

Consider
<input type=button value="Morituri te salutamur" onClick="splat">
which usually does about what you want in at least one browser.
 
H

Hal Rosser

Consider
<input type=button value="Morituri te salutamur" onClick="splat">
which usually does about what you want in at least one browser.
Some would rib one for not quoting all attribute values ("button") or for
not closing the tag (" />") or for misspelling "salutamus" or make some
comment like"until you learn html...yadda yadda" - but not me.
 
R

Richard Cornford

Hal said:
Some would rib one for not quoting all attribute values ("button")

Maybe, but advising people to quote all attribute values is justified
with the suggestion that doing so allows you to operate in ignorance of
the HTML rules about which characters are allowed in an unquoted
attribute and which would require an attribute to be quoted. The word
'button' does not include any characters that fall into the set that
would require quoting of the attribute value.
or for not closing the tag (" />")

Anyone who proposes doing that in an HTML document will be subject to
quite a critical response themselves.
or for misspelling "salutamus" or

Typically, if you attempt to criticise another's spelling on Usenet the
critical post will include at least one spelling mistake of its own ;-)
make some comment like"until you learn html...yadda yadda" -

Learning HTML prior to attempting to script HTML documents has got to be
a good idea. However, that short snippet of HTML is technically
faultless.
but not me.

That is probably for the best.

Richard.
 
R

Richard Cornford

Hal said:
Like I said, Some would criticize - but not me. I
wouldn't be that rude.

Criticism, in itself, is not rude. Indeed critical peer review is one of
the most efficient learning tools available. Providing informed
criticism, with justifications/explanations, can be a great service to
the interested student.

Where criticism becomes rude is when there is no hope of learning
anything from the originator of the criticism. I.E. when there is no
explanation or justification of the criticism, and no hope of receiving
such through further interaction with the critic.

Incidentally, you are not attributing the material you are quoting, or
marking the edits in your quotes. Both would be expected in well-formed
Usenet posts.

Richard.
 
H

Hal Rosser

Richard Cornford said:
Incidentally, you are not attributing the material you are quoting, or
marking the edits in your quotes. Both would be expected in well-formed
Usenet posts.

Richard.

I did not realize they would be expected in a threaded format like this.
Thanks for pointing it out.
 
L

Lasse Reichstein Nielsen

[attributing quotes]
I did not realize they would be expected in a threaded format like this.
Thanks for pointing it out.

It's an artifact of how usegroups work. Each news server can have its
own rules for retaining older messages. It is quite likely that people
will read a reply to a message after that message is no longer
available from their server. Even if the client wanted to, it couldn't
tell you who wrote the previous message or what it said.

/L
 
T

Thomas 'PointedEars' Lahn

Lasse said:
It's an artifact of how usegroups work.

No, it is not. (BTW: "usegroups"?) Sure, there is a technical reason for
quoting what you are replying to. However, the more important reason is
the social one of retaining context of the statement, and preventing
potential readers to dig out that references and its authors from all what
was posted before. It is a matter of efficiency, and, last but not least,
simple courtesy towards the potential reader and discussion participant.

Therefore, quoting and providing attribution as a recommended posting style
is not restricted to NetNews messages, although some forms of electronic
discussion, such as bulletin boards on the Web, tend to ignore that.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Lasse said:
It's an artifact of how usegroups work.

No, it is not. (BTW: "usegroups"?) Sure, there is a technical reason for
quoting what you are replying to. However, the more important reason is
the social one of retaining context of the statement, and preventing
potential readers from diggin out those references and the names of their
authors from all what was posted before. It is a matter of efficiency,
and, last but not least, simple courtesy towards the potential reader and
discussion participant.

Therefore, quoting and providing attribution as a recommended posting style
is not restricted to NetNews messages, although some forms of electronic
discussion, such as bulletin boards on the Web, tend to ignore that.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top