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,526
  • 4
  • 26
  • 42

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
  • 223,102
  • 54
  • 301
  • 354
1

Something like this:

var textbox = document.getElementById('myTextbox')
function setTitle () {
  document.title = textbox.value
}
textbox.onkeyup = setTitle
textbox.onchange = setTitle
Abraham
  • 19,409
  • 7
  • 31
  • 39
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
  • 28,837
  • 30
  • 92
  • 126
0

Here,

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

Just add this in your page and try!

Ahmed
  • 2,668
  • 7
  • 36
  • 65
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
  • 20,303
  • 60
  • 160
  • 239