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>
.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!
Thanks Logic Ali your solution works and is even simpler.
Originally Posted by
Logic Ali
.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.
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.
Originally Posted by
Troy III
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!
Originally Posted by
Logic Ali
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.
Originally Posted by
begood321
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.
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.
Originally Posted by
begood321
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.
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 .
Originally Posted by
begood321
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.
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 .
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>
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
Forum Rules
Bookmarks