Home › Forums › JavaScript › Update title of dynamically-loaded page?
- This topic is empty.
-
AuthorPosts
-
January 31, 2016 at 1:21 am #237523heyesParticipant
In the article/code at https://css-tricks.com/rethinking-dynamic-page-replacing-content/, what mods would be required to also update the page title (currently it remains that of the original-load page, and thus all history entries confusingly have that title too).
I apologize for asking such an open question, but I simply don’t have the brainpower to understand much of this stuff.
Please, thanks, etcetera.
January 31, 2016 at 4:15 am #237524programacaocriativaParticipantIf you try to change this title of page and don’t get success, try this and i think what you will be happy =)
<script>
title = document.getElementsByTagName(‘title’)[0].innerHTML = prefix + ‘Deleting row(s)’;window.history.replaceState(null, title, destination);
</script>January 31, 2016 at 4:29 am #237525heyesParticipantThanks.
Unfortunately, it doesn’t appear to update the title.
Having searched a lot on this issue… it seems that a downside of using Ajax to load new content the title remains that of the first page, not the subsequent page.
Apparently, jQuery Mobile has a fix (https://demos.jquerymobile.com/1.2.0/docs/pages/page-titles.html) and automatically parses the title of the page pulled via Ajax and changes the title attribute of the parent document to match… but I don’t know how to use it
January 31, 2016 at 5:21 am #237526ShikkedielParticipantWhy wouldn’t it update the url? There’s a line for that :
history.pushState(null, null, _href);
You don’t really need Modernizr, this’ll do the same :
if (history.pushState !== 'undefined')
Did you add that plugin to begin with by the way?
The page was written a while back, at this point it would be better to use
.on()
everywhere instead of.delegate()
and such…January 31, 2016 at 11:56 pm #237558heyesParticipantWhy wouldn’t it update the url? There’s a line for that…
I don’t know – this stuff is beyond my understanding.
Perhaps I misunderstood how to add it… which I did as a separate script rather than add to the original.And as regards the need for Modernizr and ‘delegate’ etc… again, I simply don’t know enough.
I’m looking for – and appreciate of – any help I can get to obtain code which will enable me to dynamically refresh part of a page and update the title appropriately.
If I could find a script to buy, I’d do so.
February 1, 2016 at 5:44 am #237567ShikkedielParticipantModernizr is a separate plugin that you’d need to add for the code to work, otherwise that line should be replaced with the one I mentioned.
if (Modernizr.history)
if (history.pushState !== 'undefined')
Should work for the rest. A live example of your efforts would otherwise be needed at this point to do any debugging…
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.