Is anyone doing this? I have a script which works in the console, but has serious problems when I embed it in the page. The main issue is that the location of that information (a comment after the </body> tag but before the </html> tag) is very difficult to identify cleanly and access in the document object.
What does your javascript you are executing in the console look like?
-Sam
Something like this:
function SessionDetails() { commentStart = "Content Deployed: " mosStart = "Session MOS: " mosEnd = "/" promoStart = "Promo:" promoEnd = ")" dtext = document.documentElement.outerHTML comment = dtext.substring(dtext.indexOf(commentStart) + commentStart.length, dtext.length) this.mos = this.comment.substring(this.comment.indexOf(mosStart) + mosStart.length, this.comment.length) this.mos = Number(this.mos.substring(0, this.mos.indexOf(mosEnd)).trim()) this.promo = this.comment.substring(this.comment.indexOf(promoStart) + promoStart.length, this.comment.length) this.promo = Number(this.promo.substring(0, this.promo.indexOf(promoEnd)).trim().substring(1, this.promo.length)) }
Hi Gawain, how about something like this (assuming you don't mind using a little jquery):
$(function() {
$("body").contents().filter(function(){
return this.nodeType == 8;
}).each(function(i, e){
if (e.nodeValue.indexOf("Content Deployed") > -1) { console.log(e.nodeValue) };
});
}); And then you can iterate over that to find what you're looking for.
The problem you are probably having is that your code runs before the html is loaded on the page. It works correctly in your console, because you manually run it after the DOM is loaded. To solve this problem you can use jQuery to wait for the page to finish loading.
tnew.$(document).ready(function() {
// code here will run after the dom has completed loading.
Ah, of course.