Advertisement
AlexTFish

PageTitler.html

Nov 8th, 2019
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.20 KB | None | 0 0
  1. <html>
  2. <head><title>Blank page</title></head>
  3. <script>
  4. function setTitle(newTitle) {
  5.   document.title = decodeURI(newTitle.replace(/_/g, " "));
  6. }
  7. function setTitleFromForm(e) {
  8.   if (e.preventDefault) { e.preventDefault(); }
  9.    
  10.   var newTitleElem = document.getElementById("newTitle");
  11.   var newTitle = newTitleElem.value;
  12.   document.title = newTitle;
  13.  
  14.   var myURL = document.location + "";
  15.   var newURL = myURL.replace(/[?#].*/, "") + "?" + newTitle;
  16.   document.location = newURL;
  17.   return false;
  18. }
  19.  
  20. window.onload=function() {
  21.   var form = document.getElementById("theForm");
  22.   form.onsubmit = setTitleFromForm;
  23.  
  24.   var myURL = document.location + "";
  25.   var currTitle = myURL.replace(/.*[?]/, "");
  26.   setTitle(currTitle);
  27.  
  28.   var input = document.getElementById("newTitle");
  29.   input.value = decodeURI(currTitle);
  30.   input.focus();
  31. }
  32.  
  33. </script>
  34. <style type="text/css">
  35.   #notes, #newtitle { width: 400px; }
  36.   #notes            { height: 300px; }
  37. </style>
  38. <body>
  39. <form id="theForm" onSubmit="setTitleFromForm" method="get">
  40.   <input type="text" id="newTitle" />
  41.   <button type="submit">Set title</button>
  42.   <br><br>
  43.   <textarea id="notes">
  44.   </textarea>
  45. </form>
  46. </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement