2

i have a html file that have this javasscript code

var a=["","#"]

so i want to add a value after the # by writing that value in the website link

like :

site.com/#value

so the js code will be

var a=["","#value"]

is that possible by using GET in php?

and how ?

Thank you

user11845248
  • 131
  • 8
  • 1
    You can read the #value in javascript using `window.location.hash` . See: https://stackoverflow.com/a/6682514/1512654 – khartnett Sep 17 '19 at 20:21

1 Answers1

1

You can do it in pure JS:

var a = ["", window.location.hash];
fonini
  • 3,243
  • 5
  • 30
  • 53
  • when i write site.com/test.html#value and check the `var a = ["", window.location.hash]; ` in the chrome inspector it didn't changed, why ? – user11845248 Sep 17 '19 at 20:32
  • i want to add the value in the html file – user11845248 Sep 17 '19 at 20:33
  • If you need to "print" the value in HTML, thats not possible, because the hash is not sent to the server. My answer only update the JS variable. – fonini Sep 17 '19 at 20:35
  • Make sure the url is loaded with the #value (press enter after typing it), then the code in chrome inspector should work – khartnett Sep 17 '19 at 20:37