Problem: Setting MSIE iframe innerHTML change relative href/src to absolute href/src

Discussion in 'Javascript' started by Soren Vejrum, Jul 5, 2003.

  1. Soren Vejrum

    Soren Vejrum Guest

    I am working on a web-based html editor using MSIE's designmode and
    iframes.

    Everything works just fine, but MSIE changes all my relative "a href"
    and "img src" links (i.e. "/index.asp") to absolute links (i.e.
    "http://localhost/index.asp") when I set the iframe's innerHTML.

    This is bad as the links are supposed to be relative. How can I avoid
    this? Any solutions/suggestions are much appreciated.

    - This (setting the innerHTML) works just fine in Mozilla/Netscape.

    - I have tried to create a selection/range and use "pasteHTML" instead
    but the result is the same.

    - I have tried to set the "html head base href" in the initial
    document loaded by the iframe but the result is the same.


    Example:

    myiframe.contentWindow.document.body.innerHTML = '<a
    href="/index.asp">xxx</a>';
    alert(myiframe.contentWindow.document.body.innerHTML);

    Output:

    <a href="http://localhost/index.asp">xxx</a>
     
    Soren Vejrum, Jul 5, 2003
    #1
    1. Advertising

  2. Soren Vejrum

    Evertjan. Guest

    Soren Vejrum wrote on 05 jul 2003 in microsoft.public.scripting.jscript:

    > I am working on a web-based html editor using MSIE's designmode and
    > iframes.
    >
    > Everything works just fine, but MSIE changes all my relative "a href"
    > and "img src" links (i.e. "/index.asp") to absolute links (i.e.
    > "http://localhost/index.asp") when I set the iframe's innerHTML.
    >
    > This is bad as the links are supposed to be relative. How can I avoid
    > this? Any solutions/suggestions are much appreciated.
    >
    > - This (setting the innerHTML) works just fine in Mozilla/Netscape.
    >
    > - I have tried to create a selection/range and use "pasteHTML" instead
    > but the result is the same.
    >
    > - I have tried to set the "html head base href" in the initial
    > document loaded by the iframe but the result is the same.
    >
    >
    > Example:
    >
    > myiframe.contentWindow.document.body.innerHTML = '<a
    > href="/index.asp">xxx</a>';
    > alert(myiframe.contentWindow.document.body.innerHTML);
    >
    > Output:
    >
    > <a href="http://localhost/index.asp">xxx</a>
    >


    You have a iframe that is not filled by an html file, but by innerHTML.

    Such "file" has no location so it cannot have relative links !!!

    So either it makes it's own absolute links or it does not wort.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jul 5, 2003
    #2
    1. Advertising

  3. Soren Vejrum

    Evertjan. Guest

    Evertjan. wrote on 05 jul 2003 in microsoft.public.scripting.jscript:
    > or it does not wort.


    "or it does not work."

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jul 5, 2003
    #3
  4. Soren Vejrum

    Evertjan. Guest

    Soren Vejrum wrote on 05 jul 2003 in comp.lang.javascript:

    > Thanks, but the iframe is actually created in an html file with a
    > dummy html file (with html, head, title, style sheet and body tags)
    > loaded for the iframe before I try to replace the innerHTML.
    >
    > In the meantime I have found a "hack" to circumvent this "error". I
    > can replace the iframe body content through "write":
    >
    > myiframe.contentWindow.document.write('<a
    > href="/index.asp">xxx</a>');
    >
    > However, I think this is ugly and would prefer to do this through the
    > DOM if at all possible.


    First who will see the "uglyness" ?

    Could you have javascript in the iframe file FETCH the value from the
    parent instead of having the parent sending it to the file ?

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jul 5, 2003
    #4
  5. "Soren Vejrum" <> writes:

    > In the meantime I have found a "hack" to circumvent this "error". I can
    > replace the iframe body content through "write":
    >
    > myiframe.contentWindow.document.write('<a href="/index.asp">xxx</a>');
    >
    > However, I think this is ugly and would prefer to do this through the DOM if
    > at all possible.


    It is (almost) DOM.

    The "write" method of the HTMLDocument interface is part of DOM 2 HTML
    (except that the DOM expects the document stream to have been openend
    by the "open" function first).

    The "contentWindow" property is not DOM 2, but the "contentDocument"
    property is, and is understood by Mozilla and Opera (but not IE, ofcourse).
    The "contentWindow" property is understood by Mozilla and IE, but should
    be equivalent to "frames['iframeName']" anyway.

    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Jul 5, 2003
    #5
    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. Nikolay Petrov

    change IFRAME src

    Nikolay Petrov, Jan 23, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    16,276
    Cor Ligthert [MVP]
    Jan 24, 2006
  2. Namshub

    Iframe Src change on form loading

    Namshub, May 30, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    15,440
    Edwin Knoppert
    May 30, 2006
  3. Christian Seberino
    Replies:
    0
    Views:
    302
    Christian Seberino
    Oct 21, 2003
  4. Joe Attardi
    Replies:
    0
    Views:
    540
    Joe Attardi
    Jan 17, 2006
  5. zero0x
    Replies:
    3
    Views:
    155
    zero0x
    Jan 6, 2007
Loading...

Share This Page