Jarry wrote:
If I take a website that has body text and <scripttags, I can do:
document.body.innerHTML = document.body.innerHTML.replace("no","yes");
but if i want to change the script as such
document.body.innerHTML =
document.body.innerHTML.replace("alert\(\"no\"\)", "alert\(\"yes\"\)");
I can't - how can I get to the section with the javascript in it?
The short answer is: for all practical purposes, you can't.
innerHTML is a non-standard property of DOM elements introduced by
Microsoft in IE. It has been widely copied by other browsers to the
extent that it is a /de facto/ standard, however, there is no public
specification for it and implementations vary.
It should only be used with simple HTML to create fully-formed DOM
objects that replace or are appended to existing DOM elements.
Replacing an element's innerHTML property does not cause code within
script elements to be executed, although some libraries include methods
to do so[1].
You might employ those methods for your attempted replacement trick,
however unless scripts are written to be executed that way, results
will be unpredictable.
1. Script elements are collected using a regular expression and their
content eval'd. A fairly crude but reliable mechanism that has some
foibles for the unwary.
Try this thread:
<URL:
http://groups.google.com.au/group/co...f42490c301de/#
>
--
Rob