I have been working on an html page for some time now and now I want to display the ever changing value of a JavaScript variable after some text in the title. ex:
___/TEXT :: TEXT: var \ _________
If this is possible in JS and html how would I do it. If I have to I am open to a little PHP, but nothing to complicated.
Asked
Active
Viewed 4,545 times
-5

zcool 99
- 27
- 1
- 8
-
https://stackoverflow.com/questions/9689109/how-to-display-javascript-variables-in-a-html-page-without-document-write – Luis felipe De jesus Munoz Jul 03 '18 at 15:13
-
@Munoz the __/ text \ ____ was just an example of how i would want it to look in the browser title. it is not code. – zcool 99 Jul 03 '18 at 15:13
-
You need to do some effort to fix it by yourself first, and next ask for a particular issue you've faced: https://stackoverflow.com/help/how-to-ask – Alejandro Jul 03 '18 at 18:15
-
request close plz. – zcool 99 Jul 04 '18 at 14:25
2 Answers
2
Look over Javascript Basics
Web-crawlers update their indices if your title changes, as a heads-up note.
let variable = "-hello world-";
document.title = "___/TEXT :: TEXT: " + variable + " \ _________";
console.log(document.title);
/*
OR
document.title = "___/TEXT :: TEXT: var \ _________";
document.title = document.title.replace('var', variable);
*/

Alex
- 2,164
- 1
- 9
- 27
-
This just looks like changing the text inside of a document. I want to display the variable in the
element. – zcool 99 Jul 03 '18 at 15:14 -
what does the `let` mean? p.s. I can code in JavaScript but there are still lost of things i don't know about >~ – zcool 99 Jul 03 '18 at 15:18
-
Refer to [`What's the difference between using “let” and “var” to declare a variable in JavaScript?`](https://stackoverflow.com/questions/762011/whats-the-difference-between-using-let-and-var-to-declare-a-variable-in-jav). `let` keyword is a strict scoped variable definition. – Alex Jul 03 '18 at 15:19
-
1Thanks never knew that. Then if I understood it right then I could use my already defined `var` instead of your `let` variable? – zcool 99 Jul 03 '18 at 15:21
-
No problem. :) Make sure to select the best answer to not keep this question hanging. – Alex Jul 03 '18 at 15:22
0
Please check this: https://developer.mozilla.org/en-US/docs/Web/API/Document/title
let title = 'my new title';
document.title = title;

schildi
- 136
- 7