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 6829873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:33:05+00:00 2026-05-26T22:33:05+00:00

I am trying to get a variable from a URL, for example if the

  • 0

I am trying to get a variable from a URL,
for example if the users can link to this page: www.example.com?var1=blabla&var2=blabla
and there are many links on this site www.example.com.
What I want is no matter where my users click, they will always see the link appended with 2 variables they got from this link www.example.com?var1=blabla&var2=blabla
for example: if there is another link

<a href="www.example.com/page1.php"/>Go to page1</a>

on www.example.com?var1=blabla&var2=blabla, they will go to page www.example.com/page1.php?var1=blabla&var2=blabla.
This is my code:

<script type="text/javascript">
$(document).ready(function() {
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1);
    var links = $('a');
    links.each(function(){
    var curLink=$(this);
    var href = curLink.attr('href');
    var newhref = href +'?'+ hashes; 
    curLink.attr('href',newhref);
    });
});
</script>

My question is: I can only make all the links on the same page append those 2 variable. If the users go to another page, it won’t do the same thing, because there is no script on it… but I can’t add same script on every pages…
And another question, I want to clear the things after question mark and append the new ones.. is that possible to do that?

Thanks!

  • 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-26T22:33:06+00:00Added an answer on May 26, 2026 at 10:33 pm

    Your code looks good to me. And from your question it appears that your problems lie outside this.

    My question is: I can only make all the links on the same page append
    those 2 variable. If the users go to another page, it won’t do the
    same thing, because there is no script on it… but I can’t add same
    script on every pages…

    If you can’t run your script on every page then you can’t modify the url’s. You will need to do it server side. If you can’t do it server side then you are out of luck.

    And another question, I want to clear the things after question mark
    and append the new ones.. is that possible to do that?

    Yes, that is certainly possible. To strip the querystring use the following code.

    var strippedHREF = window.location.href.substring(0, window.location.href.indexOf('?'));
    
    • 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 a variable from the URL, but for some reason, I
I am trying to get some xpath from xsl variable using xsl ver 1.0
I am trying to transfer a variable from the URL into a contact form
ok so im trying to get a javascript variable into a php script, this
Im trying to create my own url scheme so my android app can get
I'm trying to get a class memeber variable list at run time. I know
I am trying to get strpos to search string variable $string for the phrase
I am trying to get jquery to pick up variable that I am defining
I am trying to use a variable to get a function in a extended
I am trying to created nested dictionary variable like the below, But I get

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.