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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:49:21+00:00 2026-05-15T17:49:21+00:00

An external javascript can be used by many Web pages. How to know which

  • 0

An external javascript can be used by many Web pages. How to know which web page is using an external js script? For example, I’ve got a javascript script s.js. Is it possible that a function of s.js can check which page is using s.js?

  • 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-15T17:49:22+00:00Added an answer on May 15, 2026 at 5:49 pm

    location object has all the information about the URL the browser is currently on.

        hash        Returns the anchor portion of a URL
        host        Returns the hostname and port of a URL
        hostname    Returns the hostname of a URL
        href        Returns the entire URL
        pathname    Returns the path name of a URL
        port        Returns the port number the server uses for a URL
        protocol    Returns the protocol of a URL
        search      Returns the query portion of a URL
    

    EDIT Now, to answer the question that you actually meant to ask and that is how to track which pages are using your javascript file. I think (and I haven’t implemented something like this before) is to use the same strategy as what the analytics sites use.

    They all seem to use a variation of a tracking pixel where the browser downloads a script file (e.g. QuantServer – http://edge.quantserve.com/quant.js). The script then requests a 1×1 pixel from the google server and encodes the URL of the webpage into the address of the image. So for stackoverflow.com, the pixel URL is:

    http://pixel.quantserve.com/pixel;r=3547206;fpan=0;fpa=P0-82955756-1264139666260;ns=0;url=http%3A%2F%2Fstackoverflow.com…. (I didn’t reveal the address as it my browser sends it as I don’t really know what it reveals about me 🙂 ).

    As you can see, the site’s url is a part of the image url. On the server side you would need to have a handler that serves this image and logs the page address by extracting it from the image URL.

    The reason for why this is an image and not an AJAX request is because AJAX requests are subject to browser XSS restrictions. Basically, a browser will not make an AJAX call to a website that is not the one serving the page. This means that a page on http://www.otherpeopleswebsite.com is not allowed to make an AJAX call to http://www.mywebsite.com. There is no such restrictions on images (or javascript files for that matter).

    So a simple system for implementing something like this would do something to this effect:

    //s.js
    var oldLoad = window.onload;
    window.onload = function(){
      if (oldLoad)
        oldLoad();
        var img = document.createElement('img');
        img.setAttribute('src', 'www.mysite.com/pixel?url=' + window.location.href);
    }
    

    On the server side, pixel handler would serve a 1x1px image, set the content type to the appropriate value (ie image/gif), extract the query string and log the URL. Depending on you server technology, there are many ways to implement that.

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

Sidebar

Ask A Question

Stats

  • Questions 461k
  • Answers 462k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are a couple of online tutorials here that should… May 16, 2026 at 12:16 am
  • Editorial Team
    Editorial Team added an answer Without going to a real-time OS, you cannot expect to… May 16, 2026 at 12:16 am
  • Editorial Team
    Editorial Team added an answer If you want to restrict the search to stored procedures… May 16, 2026 at 12:16 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.