I want to change the title of page dynamically. I have lots of AJAX
request going on in my page. On each type of response I want to notify this using the title.
So, How to change the title of page through jQuery
?
I want to change the title of page dynamically. I have lots of AJAX
request going on in my page. On each type of response I want to notify this using the title.
So, How to change the title of page through jQuery
?
document.title = "newtitle"
is the only valid way as far as I know. manipulating
$("title")
will fail on IE8.
There are subtle differences between the title tag and document.title, it appears browsers treat them differently.
Why jQuery for such minor task? Use vanilla javascript:
document.title = "My new title";
More Info:
If you still want to go with jQuery, you simply do:
$("title").html("My new title");
In pure JavaScript:
document.title = "Insert title here";
the document should be fully loaded before you change it.
Reference: Document.Title at Mozilla Developer Central
<script type="text/javascript">
$(document).ready(function() {
document.title = 'blah';
});
</script>
also check this http://hancic.info/change-page-title-with-jquery
Assuming you're using the latest jQuery, doing something as simple as:
$('title').text('My new title');
should work. At least, this works doing a simple in-page javascript console test in google Chrome. You could use .html instead of .text, but generally you don't want HTML in the title tag, since that's not usually allowed and might display weirdly - with .text at least you know your new title string will be escaped and not lead to any weird behaviour.
Otherwise I expect doing something using straight javascript would be fine, such as:
document.title = 'A new title';