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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:45:29+00:00 2026-06-11T15:45:29+00:00

Possible Duplicate: How can I get query string values? Lets say, we have a

  • 0

Possible Duplicate:
How can I get query string values?

Lets say, we have a <script> tag like this in the HTML markup

<script src="/path/file.js?test=1&data=2"></script>

..is there any way to access the query-string within file.js ? window.location does not change of course, so you can’t use that for that.

If this is not possible, how can you pass data into a script file ?

  • 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-11T15:45:31+00:00Added an answer on June 11, 2026 at 3:45 pm

    Musa has the right approach here (from the comments). You can access the script tag like any other (you can use an ID to make it easy):

    <script id='my_script_1' src="/path/file.js?test=1&data=2"></script>
    

    Then just parse out the src and grab only the query string:

    var js_lib = document.getElementById('my_script_1');
    var js_url = js_lib.src;
    var js_url_pieces = js_url.split('?');
    alert(js_url_pieces[1]);
    

    Note: I’m using split for simplicity’s sake. You might want to use regex.

    If you want reload the js file, just reset the source:

    js_lib.src = js_url_pieces[0]+'?new query string';
    

    I think that should work in most browsers.

    Alternately, as others have mentioned, you might want to write more flexible functions or use global variables to achieve what you’re trying to do through _GET vars.

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

Sidebar

Related Questions

Possible Duplicate: Get query string values in JavaScript Say if,i've a URL like this
Possible Duplicate: Get query string values in JavaScript I had this pattern but it
Possible Duplicate: Get query string values in JavaScript how can i get the get
Possible Duplicate: Get entire URL, including query string and anchor I have my url
Possible Duplicate: Get query string values in JavaScript Parse query string in JavaScript http://www.example.org/search?q=example&another=test&again=more
Possible Duplicate: get name of current PHP script in include file Can an included
Possible Duplicate: How can I get an element's serialised HTML with PHP's DOMDocument? PHP
Possible Duplicate: PHP: Convert special characters to HTML character codes I have a string
Possible Duplicate: How can I get a reference to a node directly after it
Possible Duplicate: How can I get a list of all the defined variables in

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.