How do I add JavaScript to every non-index page on my Tumblr blog? -


i want add javascript code every individual post page on tumblr blog. have following, seems never show on page let alone just permalink or individual post pages. i've tried many variations here removing posts block or permalinkpage block no avail. doing wrong here?

<!-- start js --> {block:posts}     {block:permalinkpage}     <script type='text/javascript'>     __config = {             {block:date},date:'{year}-{monthnumberwithzero}-{dayofmonthwithzero} {24hourwithzero}:{minutes}:{seconds}'{/block:date}             {block:postsummary},title:{jsplaintextpostsummary}{/block:postsummary}             {block:hastags},tags:[{block:tags}'{tag}', {/block:tags}],{/block:hastags}             ,url:'{urlencodedpermalink}'     };     (function(){       var s = document.createelement('script');       s.type = 'text/javascript';       s.src = document.location.protocol + '//example.com/example.js';       (document.getelementsbytagname('head')[0] || document.getelementsbytagname('body')[0]).appendchild(s);     })();     </script>     {/block:permalinkpage} {/block:posts} <!-- end js --> 

this how solve using javascript/front end.

var path = document.location.pathname; path = path.split("/")[1]; // should return primary directory path = path.tolowercase(); // should catch your.tumblr.com/search , your.tumblr.com/search if(path === "" || path === "search")){     console.log('index or search page'); }else{    // run function here } 

basically if path url empty or equal search not run function, run function in other case.

however, mentioned not 100% robust. path might http://your.tumblr.com/# , function fail, may have build more explicit logic (you can if path !== " " empty string).

i'm still not sure why it's not idea have on every page. unless users being linked pages on site , not being routed via index page. , unless javascript code massive, cached index page (but still available other pages in case of hotlinking, etc.).

edit

as per comments below, have created basic example on test tumblr account.

the code looks this:

  var path = document.location.pathname;   path = path.split("/")[1];   path = path.tolowercase();   if(path === "" || path === "about"){     $('body').css('background','#f09');     console.log('index or page');   }else{     $('body').css('background','#fc0');     console.log('other page');   } 

the tumblr page using here: http://sg-test.tumblr.com/

(i not think there search page, search function block insert or activate within template , available on every page.)

the function checks index page (empty primary directory), or page (substitute 'search' or page if needs be).

console logs output on every page. , if path matches index or have set body colour pink, or else every other page orange.

http://sg-test.tumblr.com/about (pink background)

http://sg-test.tumblr.com/post/134796799695/post-title (orange background)

by logic should easy adapt function execute code if meets path variable requirements, in first example.

as mentioned though there issue http://sg-test.tumblr.com/#. still index page, our test returning false empty directory, though tumblr mapping home page.


Comments