Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy document object works in IE but not in FF

    Hi Guys,

    The following snippet works perfectly in IE. I can't get code below to work in FF. The code returns file path and path when saved and opened as html file.

    Thanks for your help.


    <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
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,918
    Thanks
    56
    Thanked 545 Times in 542 Posts
    I would try with
    Code:
    myDiv1.innerHTML = window.location.pathname;
    myDiv2.innerHTML = full_path;

  • #3
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks xelawho for your reply. I had that exact experssion previously, didn't make a difference. You'll see if you save as html file then open in url window. Still trying to solve but any help is welcome.

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,918
    Thanks
    56
    Thanked 545 Times in 542 Posts

    using innerHTML I get the same output in IE, FF and Chrome...

  • #5
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah you right works on my home pc, strange I think I tried on my work computer and it didn't work. Thanks for your help. I will confirm and reply when I go to work Monday.

  • #6
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/>");

  • #8
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #9
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    no, because it uses activex objects which are exclusive to IE

  • #10
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Guys for your response. How do I replace \ with : in code below. Try it in code below but it's not working.

    Code:
    cmCreatePageviewTag("<<label id="myDiv1"></label>>","<<label id="myDiv2"></label>>");
    
    <script type="text/javascript">
    
    document.getElementById("myDiv1").innerHTML = window.location.pathname;
    
    document.getElementById("myDiv2").innerHTML = top.location.pathname.replace(/\\/g,":").replace( /\/[^\/]*$/, ":" );
    
    alert("cmCreatePageviewTag(\"<" + window.location.pathname + "," + top.location.pathname.replace(/\\/g,":").replace( /:[^:]*$/, ":" ) + ">\")");
    
    </script>

  • #11
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nevermind guys I got it working, here is the solution below plus uppercase function:

    Code:
    cmCreatePageviewTag("<<label id="myDiv1"></label>>","<<label id="myDiv2"></label>>");
    
    <script type="text/javascript">
    
    document.getElementById("myDiv1").innerHTML = window.location.pathname.split('/').join(':').toUpperCase();
    
    document.getElementById("myDiv2").innerHTML = top.location.pathname.replace(/\\/g,"/").replace( /\/[^\/]*$/, "" ).split('/').join(':').toUpperCase();
    
    </script>


  •  

    Posting Permissions

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