www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: document object works in IE but not in FF

  1. #1
    Join Date
    Sep 2012
    Posts
    17

    Unhappy document object works in IE but not in FF

    <html>
    <body>

    cmCreatePageviewTag("<<label id="myDiv1"></label>>","<<label id="myDiv2"></label>>");

    <script type="text/javascript">

    var myDiv1 = document.getElementById("myDiv1");
    var myDiv2 = document.getElementById("myDiv2");
    myDiv1.innerText = window.location.pathname;

    var path = top.location.pathname;
    if (document.all) {
    path = path.replace(/\\/g,"/");
    }
    path = path.substr(0,path.lastIndexOf("/"));
    var full_path = path;
    myDiv2.innerText = full_path;

    </script>

    </body>
    </html>

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    .all .innerText are IE only and should be discarded:
    Code:
    <script type="text/javascript">
    
    document.getElementById("myDiv1").innerHTML = window.location.pathname;
    
    document.getElementById("myDiv2").innerHTML = top.location.pathname.replace(/\\/g,"/").replace( /\/[^\/]*$/, "/" );
    
    </script>
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  3. #3
    Join Date
    Sep 2012
    Posts
    17
    Thanks Logic Ali your solution works and is even simpler.

  4. #4
    Join Date
    Jan 2011
    Posts
    117
    Quote Originally Posted by Logic Ali View Post
    .all .innerText are IE only and should be discarded:
    That's not true at all - the only browser not supporting the standard innerText property,
    is FX.

  5. #5
    Join Date
    Sep 2012
    Posts
    17
    Thanks for your input Troy.

    Guys,

    Is there a way to get the value of the output html to show within the same page view source, without hardcoding it inside the javascript?

    I need to be able to produce this value in multiple individual pages.

    Thank for any help or suggestions.

  6. #6
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by Troy III View Post
    That's not true at all - the only browser not supporting the standard innerText property,
    is FX.
    More latterly other browsers may have adopted innerText, but there's nothing standard about it.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  7. #7
    Join Date
    Jan 2011
    Posts
    117
    Quote Originally Posted by Logic Ali View Post
    More latterly other browsers may have adopted innerText, but there's nothing standard about it.
    ...there's a lesser truth in this statement than in previous!
    1. All the browsers supporting document.all, innerHTML and innerText: supported them since their beginings.
    The only browser *****ing about, was and is, FX.
    2. innerText, is the current W3C HTML5 Standard, and together with the outer[counterparts], are the most powerful and usable features of content manipulation.


    Further more, your "return should be used only as the last and unconditional statement in the function." signiture statement, is also incorrect.
    That is -If you care to know.

  8. #8
    Join Date
    Jan 2011
    Posts
    117
    Quote Originally Posted by begood321 View Post
    Thanks for your input Troy.

    Guys,

    Is there a way to get the value of the output html to show within the same page view source, without hardcoding it inside the javascript?

    I need to be able to produce this value in multiple individual pages.

    Thank for any help or suggestions.
    You can grab the outerHTML of the element, and paste it as innerText of your target element.

  9. #9
    Join Date
    Sep 2012
    Posts
    17
    Thanks Troy, I'm not a javascript expert can you show me how to do it. If I find solution before your reply I'll post it.

  10. #10
    Join Date
    Jan 2011
    Posts
    117
    Quote Originally Posted by begood321 View Post
    Thanks Troy, I'm not a javascript expert can you show me how to do it. If I find solution before your reply I'll post it.
    The problem with your question is that it's not specific and I'm not sure I understand your exact aim in here.
    If your requirement is to say: take a piece of your hardcoded HTML and display it as HTML without re-writing it.

    Try:
    Code:
    myTarget.innerText = myElement.outerHTML; //all
    myTarget.textContent = myElement.outerHTML; //fx
    That's about as simple as it can get...

    p.s.:
    If you want to preserve all whitespaces and newlines exactly as in source,
    make a <pre> element a target.

  11. #11
    Join Date
    Sep 2012
    Posts
    17
    Basically I want to be able to show result of output html in view source, below as an eg:

    cmCreatePageviewTag("</C:/Users/Test/Documents/test.html>","</C:/Users/Test/Documents/>");
    Last edited by begood321; 09-09-2012 at 10:17 PM.

  12. #12
    Join Date
    Jan 2011
    Posts
    117
    Quote Originally Posted by begood321 View Post
    Basically I want to be able to show result of output html in view source, below as an eg:

    cmCreatePageviewTag("</C:/Users/Test/Documents/test.html>","</C:/Users/Test/Documents/>");
    This is all Greek to me.

  13. #13
    Join Date
    Sep 2012
    Posts
    17
    I just want to be able to save output html in viewsource of the same page as follows:

    cmCreatePageviewTag("<fullpath/file>","<fullpath>");

    fullpath/file is equivalent to <label id="myDiv1"></label> and fullpath is equivalent to <label id="myDiv2"></label>

    so when I do a viewsource afterwards I would see:

    cmCreatePageviewTag("<fullpath/file>","<fullpath>");

    instead of:

    cmCreatePageviewTag("<<label id="myDiv1"></label>>","<<label id="myDiv2"></label>>");
    Last edited by begood321; 09-10-2012 at 09:03 AM.

  14. #14
    Join Date
    Sep 2012
    Posts
    17
    Guys I get the below code to work in IE, but not in FF. Any ideas getting it to work in FF?

    Code:
    <html>
    <head>
    cmCreatePageviewTag("<<label id="myDiv1"></label>>","<<label id="myDiv2"></label>>");
    <script language="javascript">
    <!-- works in IE only -->
    function WriteToFile()
    {
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var s = fso.CreateTextFile("C:\\Text.txt", true);
    document.getElementById("myDiv1").innerHTML = window.location.pathname;
    document.getElementById("myDiv2").innerHTML = top.location.pathname.replace(/\\/g,"/").replace( /\/[^\/]*$/, "/" );
    s.WriteLine('<script language=\"javascript\"\>');
    s.WriteLine("cmCreatePageviewTag(\"<" + window.location.pathname + "," + top.location.pathname.replace(/\\/g,"/").replace( /\/[^\/]*$/, "/" ) + ">\")");
    s.WriteLine('\</script\>');
    s.Close();
    }
    </script>
    </head>
    <body onLoad="WriteToFile()">
    
    </body>
    </html>

  15. #15
    Join Date
    Jan 2011
    Posts
    117
    That's because only IE provides an FSO api

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles