2

Just like when you ask a question on this website, as you type the title in the tab changes to whatever you have typed in the question box. How do you access this?

John
  • 1,486
  • 4
  • 24
  • 39

5 Answers5

4

Quick'n'dirty:

document.title = prompt('sup bro ?');

If you don't want a modal input dialog, you need to catch some events for any <input> box.

document.getElementById('inputBoxId').addEventListener('keypress', function( event ) {
    if( event.keyCode === 13 ) {  // return ?
        document.title = this.value;
    }
}, false);

addEventListener needs to get replaced by attachEvent for IE<9

jAndy
  • 212,463
  • 51
  • 293
  • 348
1

Something like this:

var textbox = document.getElementById('myTextbox')
function setTitle () {
  document.title = textbox.value
}
textbox.onkeyup = setTitle
textbox.onchange = setTitle
Abraham
  • 18,307
  • 7
  • 30
  • 38
0

You have to make your title tag, in html dynamic, So the title tag which appears as a element of head tag. You have to either use javascript or some server language to set its value.

sushil bharwani
  • 27,522
  • 29
  • 88
  • 122
0

Here,

<script language="javascript">
 document.title = "The new title goes here.";
</script>

Just add this in your page and try!

Ahmed
  • 2,238
  • 5
  • 32
  • 58
0

If you are using a server side scripting like PHP or ASP, its quite simple. Just generate a text based on your URL.

For example, if you have a php page mypage.php, you may use;

<title><?php echo $_GET["title"]; ?></title> //will display page title "MyPage"

if you call your php page like mypage.php?title=MyPage

Not JavaScript, but just for your information.

Alfred
  • 19,306
  • 58
  • 155
  • 232