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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:42:41+00:00 2026-05-14T01:42:41+00:00

Through JavaScript I am appending one query parameter to the page url and I

  • 0

Through JavaScript I am appending one query parameter to the page url and I am facing one strange behaiviour.

<div>
    <a href="Default3.aspx?id=2">Click me</a>
</div>


$(function () {
    window.location.href = window.location.href + "&q=" + "aa";
});

Now I am appending &q=aa in default3.aspx and in this page the &q=aa is getting added continuously, causing the URL to become:

 http://localhost:1112/WebSite2/Default3.aspx?id=2&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa

One would say just pass it like <a href="Default3.aspx?id=2&q=aa">Click me</a>, but I cant do that. The value of this query parameter is actually the value of an HTML element which is in default3.aspx. I have to add it in runtime.

What are the ways to achieve this?

  • 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-14T01:42:41+00:00Added an answer on May 14, 2026 at 1:42 am

    The reason this happens is because if you change the window.location value the browser will perform a redirect to the new location and as you are doing this in the document.ready this happens indefinitely.

    Before doing this redirect you might want to check if the current url already contains these parameters.

    $(function () {
        var suffix = '&q=aa';
        var currentUrl = window.location.href;
        if (currentUrl.match(suffix + '$') != suffix) {
            window.location.href = window.location.href + suffix;
        }
    });
    

    Remark: Using javascript for this purpose seems to me like a bad idea. I would perform this redirect on the server side which would be more reliable. In your default.aspx page:

    protected void Page_Load(object sender, EventArgs e) 
    {
        var q = Request["q"];
        if (string.IsNullOrEmpty(q))
        {
            // q parameter has not been set => redirect
            Response.Redirect("/default.aspx?q=aa");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I go through all external links in a div with javascript, adding
I'm using JSLint to go through JavaScript, and it's returning many suggestions to replace
I want to make a link call a Javascript function through the onclick event
Does the for…in loop in Javascript loop through the hashtables/elements in the order they
Reading through this question on multi-threaded javascript, I was wondering if there would be
I'm learning JavaScript and while browsing through the jQuery library I see : (colon)
How do you tell if caps lock is on using JavaScript? One caveat though:
Ok: I've got an UpdatePanel on an aspx page that contains a single Placeholder.
Here is function , <script type=text/javascript> $(document).ready(function() { getRecordspage(1, 5); $(a.page-numbers).click(function() { alert(1); getRecordspage($(this).text(),
Recently, I ran some of my JavaScript code through Crockford's JSLint , and it

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.