Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Update title of dynamically-loaded page?

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #237523
    heyes
    Participant

    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.

    #237524
    programacaocriativa
    Participant

    If 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>

    #237525
    heyes
    Participant

    Thanks.

    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

    #237526
    Shikkediel
    Participant

    Why 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…

    #237558
    heyes
    Participant

    Why 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.

    #237567
    Shikkediel
    Participant

    Modernizr 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…

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.