CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   DOM and JSON scripting (http://www.codingforums.com/forumdisplay.php?f=15)
-   -   document object works in IE but not in FF (http://www.codingforums.com/showthread.php?t=272520)

begood321 09-07-2012 11:05 PM

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>

xelawho 09-08-2012 12:32 AM

I would try with
Code:

myDiv1.innerHTML = window.location.pathname;
myDiv2.innerHTML = full_path;


begood321 09-08-2012 04:07 PM

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.

xelawho 09-08-2012 05:12 PM

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

begood321 09-08-2012 05:48 PM

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.

begood321 09-09-2012 02:15 PM

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.

begood321 09-10-2012 04:17 AM

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/>");

begood321 09-10-2012 06:24 PM

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>


DanInMa 09-10-2012 06:28 PM

no, because it uses activex objects which are exclusive to IE

begood321 09-22-2012 01:31 PM

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>


begood321 09-23-2012 02:10 PM

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>



All times are GMT +1. The time now is 04:41 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.