I am using some nested layouts in Ruby on Rails, and in one of the layouts i have a need to read in a string from a div and set that as the title of the document. What is correct way (if any) to set the title of the document?
<script type="text/javascript">
$(document).ready(function() {
// ???
});
</script>
This works fine in all browser...
Works in IE too
The following should work but it wouldn't be SEO compatible. It's best to put the title in the title tag.
If you have got a serverside script get_title.php that echoes the current title session this works fine in jQuery:
Like this:
Be sure to set a default-title if you want your site to be properly indexed by search-engines.
A little tip:
document.title was not working for me.
Here is another way to do it using JQuery
Do not use
$('title').text('hi')
, because IE doesn't support it.It is better to use
document.title = 'new title';