Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-07-2012, 11:05 PM   PM User | #1
begood321
New Coder

 
Join Date: Sep 2012
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
begood321 is an unknown quantity at this point
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>
begood321 is offline   Reply With Quote
Old 09-08-2012, 12:32 AM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
I would try with
Code:
myDiv1.innerHTML = window.location.pathname;
myDiv2.innerHTML = full_path;
xelawho is offline   Reply With Quote
Old 09-08-2012, 04:07 PM   PM User | #3
begood321
New Coder

 
Join Date: Sep 2012
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
begood321 is an unknown quantity at this point
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.
begood321 is offline   Reply With Quote
Old 09-08-2012, 05:12 PM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough

using innerHTML I get the same output in IE, FF and Chrome...
xelawho is offline   Reply With Quote
Old 09-08-2012, 05:48 PM   PM User | #5
begood321
New Coder

 
Join Date: Sep 2012
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
begood321 is an unknown quantity at this point
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 is offline   Reply With Quote
Old 09-09-2012, 02:15 PM   PM User | #6
begood321
New Coder

 
Join Date: Sep 2012
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
begood321 is an unknown quantity at this point
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 is offline   Reply With Quote
Old 09-10-2012, 04:17 AM   PM User | #7
begood321
New Coder

 
Join Date: Sep 2012
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
begood321 is an unknown quantity at this point
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 is offline   Reply With Quote
Old 09-10-2012, 06:24 PM   PM User | #8
begood321
New Coder

 
Join Date: Sep 2012
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
begood321 is an unknown quantity at this point
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>
begood321 is offline   Reply With Quote
Old 09-10-2012, 06:28 PM   PM User | #9
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
no, because it uses activex objects which are exclusive to IE
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 09-22-2012, 01:31 PM   PM User | #10
begood321
New Coder

 
Join Date: Sep 2012
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
begood321 is an unknown quantity at this point
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 is offline   Reply With Quote
Old 09-23-2012, 02:10 PM   PM User | #11
begood321
New Coder

 
Join Date: Sep 2012
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
begood321 is an unknown quantity at this point
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>
begood321 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:39 PM.


Advertisement
Log in to turn off these ads.