0

I have searched so much for this. How do I make JS make a link that goes something along the lines of example.com/index.php#number?

Example of what i mean - https://gyazo.com/428ea0c819d340a699a328baaf4c1c1f

4
  • Do you mean you want to create an anchor element and add it to the page? Commented Nov 25, 2021 at 10:23
  • Can you elaborate? Would you like to link to anywhere in the same page or are you asking to create anchored links? Commented Nov 25, 2021 at 10:24
  • Basically, I saw a video that was 'showing' how to make a video chat site and it would generate a link with random numbers and letters. It looked like this: gyazo.com/428ea0c819d340a699a328baaf4c1c1f edit: the 'showing' means it was just telling you how to copy and paste code Commented Nov 25, 2021 at 10:28
  • Okay now I get what you meant Commented Nov 25, 2021 at 10:34

2 Answers 2

1

Lets say that you have your base address, "http://www.example.com/index.php", what you want to do is to add a new part to the url

const base = "http://www.example.com/index.php"
let number  = 42
location.href = base + "#" + number

which will redirect you to "http://www.example.com/index.php#42"

Sign up to request clarification or add additional context in comments.

Comments

1

I am not really sure what are you trying to achieve here but I hope this helps.


let a = document.createElement('a');
let url_link_title = document.createTextNode("Your Title Here.");
a.appendChild(url_link_title);
a.title = "Your Title Here";
a.href = "http://yoursampleaddress.com";
document.body.appendChild(a);
 

1 Comment

see the comments under the post

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.