Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > using javascript to modify an HTML page?

Reply
Thread Tools

using javascript to modify an HTML page?

 
 
William Krick
Guest
Posts: n/a
 
      10-02-2006
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?

 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      10-02-2006
"William Krick" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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>".


 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      10-02-2006


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[i];
var iElement = document.createElement('i');
bElement.parentNode.replaceChild(iElement, bElement);
while (bElement.hasChildNodes()) {
iElement.appendChild(bElement.firstChild);
}
}


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
William Krick
Guest
Posts: n/a
 
      10-06-2006

Martin Honnen wrote:
> 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[i];
> 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/activeco...devletter.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read/modify a cell of a HTML table with a JavaScript Stefan Mueller Javascript 1 11-10-2005 11:53 PM
Modify HTML using applet (org.w3c.dom.* ?) Beat Zahnd Java 3 04-14-2005 02:31 PM
How to read the BODY of HTML file from another HTML file using javascript? Dhanasankar S via DotNetMonster.com ASP .Net 1 02-28-2005 05:51 PM
How to read the BODY of HTML file from another HTML file using javascript? Dhanasankar S via DotNetMonster.com ASP .Net 0 02-26-2005 10:58 AM
Still confused...using an HTML Control to modify an HTML tag's value darrel ASP .Net 6 10-15-2004 07:16 PM



Advertisments