Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3612536
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:00:41+00:00 2026-05-18T22:00:41+00:00

I am trying to get one part of a URL to insert into another.

  • 0

I am trying to get one part of a URL to insert into another.

URL in address bar will read domain.com/test.php?/12345 then link in page must become domain.com/do/Login/12345 (this end number will change for every user)

(Note that I can’t change the URL domain.com/test.php?/12345 as this has already been set by the site owner.)

For the URLs above I had to remove the http://www. part above as new user can’t submit more than one link for spam prevention. The final script should include http://www.

You will be able to see that all I need to get is the number at the end ie 12345 but I’m not too sure how to achieve this (javascript beginner). This is what I have so far:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Path test</title>
</head>

<body>

<script>
// get URL eg http://www.domain.com/test.php?/12345
newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;
</script>

<script>
//write new domain then add user number ie 12345
document.write('http://www.domain.com/do/Login/' + window.location.pathname);
</script>
</body>
</html>

This obviously does not work but shows where I got to.

I’ve had some luck using a script I found at http://www.sitepoint.com/forums/showthread.php?t=244955 but it only worked with filenames with an extension name on like .html, .php etc.

Any ideas?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:00:42+00:00Added an answer on May 18, 2026 at 10:00 pm

    First, you need to get the part of the url after the question mark. This is available in the

     window.location.search
    

    variable. Note that that already includes the “/”. Then you need to create the actual link. document.write(‘http://…) won’t work because that will just write it in text form and will not be an actual anchor tag. For that you need something like:

    document.getElementById("yourLink").href = "http://domain.com/do/Login" + window.location.search
    

    don’t forget to put an anchor tag in the html with an id that matches the element in the getElementById() method above. If you don’t want to put an anchor tag in your html markup, you can create one with javascript with something like:

    var link = document.createElement('a');
    link.href = "http://domain.com/do/Login" + window.location.search;
    document.body.appendChild(link);
    

    This may need further adjusting to your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get one object from this array and print all of its
I'm trying to get a one-to-many relationship working with grails/gorm. I don't understand how
I have been trying to get this one section of my UI to immediatly
Hello every One i am trying to get Ist date of All months in
Trying to get MGTwitterEngine app to build. Getting one pesky error. The following ERROR.
I'm trying to get java to perform one action after one click and then
I'm trying to get content from an RSS2 feed from one of my sites
Hi I am trying to get this script to show random colours one after
I'm having one hell of a time trying to get my databinding to work
So I'm trying to get a navigation layout for a header like the one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.