473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Changing Script

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?

Dec 21 '06 #1
1 1123
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

Dec 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: LRW | last post by:
Sorry to crosspost, but I have no idea if this is more a PHP question of general Linux question. I have a script that makes changes to image files, montages them into a jpg, and creates a Web...
5
by: Jim Marquardson | last post by:
Hi, I've struggled with this for a while now, so I'm asking for help. I am trying to click on a link in one page, have that link open up in a new window, and set that newly opened window's...
2
by: rpesq | last post by:
Hi, I Need help changing the content of a DIV. I sincerely researched the issue and have not found a solution except to scrap the idea and stick with the iframe code that I had been using. My...
2
by: Gopal | last post by:
Hi, I've a module report.py having a set of funtions to open/close/write data to a log file. I invoke these functions from another module script.py. Whenever I'm changing something in...
7
by: Stefan Finzel | last post by:
Hi, is there a way to change the display property on Windows Mobile 2003 SE Mobile/Pocket Internet Explorer? See following example. Please note: visibilty property has the same problem. Is...
12
by: GaryDean | last post by:
In the original post I failed so indicate that I am using framework 1.1....... I need to be able to change the background color of a page from code. I found an answer to this question in...
4
by: libsfan01 | last post by:
hey this code wont work for my iframe in safari, i cant change the page by changing the src with js: <script language="javascript"> function loadcontent(page) {...
6
by: Velislav | last post by:
Hi, I have a client script block, which is registered in my Page_Load. However a button may result in the need to change the script which I've registered. Obviously the OnClick event occurs...
3
by: bulldog8 | last post by:
I am having problems with changing a frames source file for Mozilla (1.5.0.4). The followig code works for IE: <script type="text/javascript"> var imgP = new Image(); function...
1
Ajm113
by: Ajm113 | last post by:
I find it odd all my scripts doesn't change the logged in person's name on any other page, but my threads page. I have no idea why! I looked over the script and saw nothing changing the session...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.