using javascript to modify an HTML page?

W

William Krick

I know that you can use the javascript document.write() method to
inject new content into a page.

Is it possible to _modify_ an HTML page?

For example, say I wanted to go through the current page and change
every <B></B> to <I></I>?

Is this possible? If so, how?
 
M

McKirahan

William Krick said:
I know that you can use the javascript document.write() method to
inject new content into a page.

Is it possible to _modify_ an HTML page?

For example, say I wanted to go through the current page and change
every <B></B> to <I></I>?

Is this possible? If so, how?

How does one "inject new content into a page" if it's someone else's
page delivered over the Internet via a Web browser?

What is your purpose and how would you want it to work?

If are viewing an external Web site and want to change tags then you'll
have to download the page, change image and link references, change
the tags, save it locally, then open it up in a browser.

Potentially this could be done via scripting -- like an HTA.

Also, many sites use CSS' "'font-weight:bold" instead of "<b></b>".
 
M

Martin Honnen

William Krick wrote:

For example, say I wanted to go through the current page and change
every <B></B> to <I></I>?

var bElements = document.getElementsByTagName('b');
for (var i = bElements.length - 1; i > -1; i--) {
var bElement = bElements;
var iElement = document.createElement('i');
bElement.parentNode.replaceChild(iElement, bElement);
while (bElement.hasChildNodes()) {
iElement.appendChild(bElement.firstChild);
}
}
 
W

William Krick

Martin said:
William Krick wrote:

For example, say I wanted to go through the current page and change
every <B></B> to <I></I>?

var bElements = document.getElementsByTagName('b');
for (var i = bElements.length - 1; i > -1; i--) {
var bElement = bElements;
var iElement = document.createElement('i');
bElement.parentNode.replaceChild(iElement, bElement);
while (bElement.hasChildNodes()) {
iElement.appendChild(bElement.firstChild);
}
}



I haven't tested it yet, but it looks like it should work. Thanks for
your help.

Basically, I'm looking for a better way to deal with the new IE
<OBJECT> tag problem. I'm thinking that if I change all the <OBJECT>
tags in my HTML pages to something else like <XOBJECT>, then call the
code above on page load to rewrite all the <XOBJECT> tags to <OBJECT>,
it should work.

At least on the surface, it seems like a simpler solution than the
alternatives proposed by Adobe...

http://www.adobe.com/devnet/activecontent/articles/devletter.html
 

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
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top