Whenever I load a blog post onto the page with Ajax, I set the page <title>
to "My Blog - BLOGPOST_TITLE".
Of course "My Blog - " appears in my application layout as well.
The question is, how do I tell my Javascript about the string "My Blog - " without duplicating it in my code?
Whenever I load a blog post onto the page with Ajax, I set the page <title>
to "My Blog - BLOGPOST_TITLE".
Of course "My Blog - " appears in my application layout as well.
The question is, how do I tell my Javascript about the string "My Blog - " without duplicating it in my code?
Share Improve this question asked Jun 2, 2009 at 6:27 Tom LehmanTom Lehman 89.4k72 gold badges205 silver badges279 bronze badges2 Answers
Reset to default 7Before Ajax is sent to server store document.title value ("My Blog") to some variable. Then when response arrives set document.title to document.title + ' - ' + BLOGPOST_TITLE
so you have in HTML:
... < title>My Blog< /title> ...
and in JS:
var TITLE = document.title; function getBlogSpotEntry() { Ajax.Request(url, { onSuccess: function(response) { var entryTitle = getTitle(response.responseText); document.title = TITLE + " - " + entryTitle; } }) }
I would go this way (dirty, but works well):
document.myTitlePrefix = 'My Blog - '
and then update title as
document.title = document.myTitlePrefix + blogPostTitle