using javascript to modify an HTML page?

Discussion in 'Javascript' started by William Krick, Oct 2, 2006.

  1. 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?
     
    William Krick, Oct 2, 2006
    #1
    1. Advertising

  2. William  Krick

    McKirahan Guest

    "William Krick" <> wrote in message
    news:...
    > 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>".
     
    McKirahan, Oct 2, 2006
    #2
    1. Advertising

  3. 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);
    }
    }


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Oct 2, 2006
    #3
  4. 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;
    > 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
     
    William Krick, Oct 6, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. darrel
    Replies:
    6
    Views:
    478
    darrel
    Oct 15, 2004
  2. MattB
    Replies:
    1
    Views:
    526
    Saravana
    Jan 6, 2005
  3. Beat Zahnd
    Replies:
    3
    Views:
    7,439
    Beat Zahnd
    Apr 14, 2005
  4. Stefan Mueller
    Replies:
    1
    Views:
    100
    McKirahan
    Nov 10, 2005
  5. Duke
    Replies:
    1
    Views:
    178
    Tom de Neef
    Apr 18, 2008
Loading...

Share This Page