javascript - Set HTML <title> tag values dynamically -
i have html page. aim set <title>
tag dynamically.
using ajax call data inserted inside title tag below
$.get("/" + $.flydubai.config.currentlanguagecode + "/error/pagetitle/", function (data) { document.title = data; });
now, want update not browser title html <title></title>
tag itself. possible? tried these:
document.getelementbyid('ttl').innerhtml = 'world'; ttl.innerhtml = 'world'; document.getelementsbytagname('title')[0].innerhtml = 'world'; document.queryselector.apply(document,['title']).innerhtml = 'world'; document.queryselectorall.apply(document,['title'])[0].innerhtml = 'world';
these change client side (i.e., browser title).
you can't change text within tag without browser detecting , refreshing it.
if need change tag , tag must yes or yes @ , add second title tag.
if utilize:
document.title='my new title';
changes made first tag.
though don't see major benefit, purpose of title tag, change window title.
also, when want modify text, use .innertext
rather .innerhtml
.
Comments
Post a Comment