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

  • Home
  • SEARCH
  • 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 6802703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:15:18+00:00 2026-05-26T19:15:18+00:00

If the current page URL has an argument ‘myid1’ or ‘myid2’ in the querystring,

  • 0

If the current page URL has an argument ‘myid1’ or ‘myid2’ in the querystring, for each link in my webpage with class ‘rewrite’, I want the link href’s querystring to be replaced by the current page URL’s querystring. I’m using the code given below. Since I’m new to javascript, I’m not sure if its optimized. I want it to execute as fast as possible. Please help. Thanks in advance 🙂

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>

<script type="text/javascript">
$(function() {
    var requestid = gup('myid1');
    if (requestid) {
        $("a.rewrite").each(function() {
            var base = this.href;
            var pos = base.indexOf("?");
            if (pos != -1) {
                base = base.substr(0, pos);
            }
            this.href = base + "?myid1=" + requestid;
        })
    }
    var requestid2 = gup('myid2');
    if (requestid2) {
        $("a.rewrite").each(function() {
            var base = this.href;
            var pos = base.indexOf("?");
            if (pos != -1) {
                base = base.substr(0, pos);
            }
            this.href = base + "?myid2=" + requestid2;
        })
    }
})

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
</script>

<a href="http://www.website.com/?someid=1234" class="rewrite">Hyperlink</a>
  • 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-26T19:15:19+00:00Added an answer on May 26, 2026 at 7:15 pm
    $(function() {
        var requestid = gup('myid1');
        var requestid2 = gup('myid2');
    
        if (requestid || requestid2) {
            $("a.rewrite").each(function() {
                var base = this.href;
                var pos = base.indexOf("?");
                if (pos != -1) {
                    base = base.substr(0, pos);
                }
    
                if (requestid){
                    this.href = base + "?myid1=" + requestid;
                    if (requesid2){
                        this.href += "?myid2=" + requestid;
                    }
                } else {
                    this.href = base + "?myid2=" + requestid;
                }
    
            })
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If the current page URL has an argument 'myid1' in the querystring, for each
When using the Url view helper to build links, if the current page has
Currently every page in my current location has a web-url as follows. /test/test In
How can you modify the URL for the current page that gets passed to
If my current url is www.example.com/thank-you, how do I echo out the page name
Using Php I would like to extract the current Url of a page including
I reference the current page in a class with Page page = HttpContext.Current.CurrentHandler as
I have a page of search results, each of which has an icon to
I have a -link element that has href link to page, but I have
I have the following Helper that gets the FULL url of the current page

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.