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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:50:05+00:00 2026-06-18T18:50:05+00:00

I have this script to replace a word: var url = window.location.toString(); window.location =

  • 0

I have this script to replace a word:

var url = window.location.toString();
window.location = url.replace(/(\?sort=name|size)/, 'date');

and this one meant to append a text to the end of a string:

var orig = location.href;
location.replace(orig+'?sort=date');

How to combine them into one script so the text only gets appended when the ?sort parameter isn’t already there?

The ?sort parameter is supposed to be always at the end of a string, if that matters.

  • 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-06-18T18:50:06+00:00Added an answer on June 18, 2026 at 6:50 pm
    var url = window.location.toString();
    var re = /(\?sort=name|size)/;
    window.location = re.test(url) ? url.replace(re, 'date') : url + "?sort=date";
    

    Side note: I think you meant '?sort=date' instead of just 'date' in your replace?

    So window.location = re.test(url) ? url.replace(re, '?sort=date') : url + "?sort=date";

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

Sidebar

Related Questions

I have this script. <script type='text/javascript' charset='utf-8'> $(window).load(function(){ window.loadIframe = function(frame) { var link
I have an URL like this: http://site.com/galleries/galleryname/imageID123/lightbox/ and using a script to replace the
I have script file which replaces one word with other in files . this
I have a simple script that does some search and replace. This is basically
I have this script: #!/var/home/cherry/opt/perl use Test::More; use DBI; use Test::mysqld; use Data::Dumper; my
I am looking for some help. I have found this script that sort of
I have this download script which works perfectly, but one the file is downloaded,
I have this JavaScript code: <script type=text/javascript> function timeMsg() { var t=setTimeout(doRedirect(),10000); } function
I have this script that needs to replace a file extension and it is
I have this script: <?php ob_start(); $get = $_GET['q']; $pspell = pspell_new('en','canadian','','utf-8',PSPELL_FAST); function spellCheckWord($word)

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.