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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:34:50+00:00 2026-06-12T04:34:50+00:00

I am trying to write some JavaScript where I can pass the path of

  • 0

I am trying to write some JavaScript where I can pass the path of the current page URL to another function ; specifically would like to add it as a a value in a custom variable for Google Analytics. However, since I don’t know JavaScript, I thought it would be best to see if I can pass the variable to a simple alert. Alas, I can not. I have checked out several posts on this site and can’t get this to work. Some of the threads I’ve checked are:

need to pass variable to function
How to pass this variable to this function?
Pass variable to external javascript?

I’ve also tried Google and some JavaScript tutorials, and playing around with single, double quotes, brackets, etc…nothing works. Can anyone help please? Thank you.

            <script type="text/javascript">
            $(document).ready(function() {
                var pdpURL = window.location.pathname;
            });
            function popup() {
                alert('pdpURL');
            }
            </script>

The pop up appears but it just says pdpURL in it rather than the URL.

  • 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-12T04:34:52+00:00Added an answer on June 12, 2026 at 4:34 am

    First of all, you don’t need quotes around your variable name when you call it. Secondly, that variable is scoped to the $(document).ready() function, and as such will not be accessible to your other function. The variable must be global for you to be able to do this, which you can do by declaring the variable outside of your functions.

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

Sidebar

Related Questions

I'm trying to write a javascript function that adds some DOM nodes to the
I'm currently trying to learn OO Javascript so I can write some cleaner code.
I am trying to write some front end Javascript tests that can test drag
I would like to have some Javascript code running in a web browser write
I'm trying to write some JavaScript for my website that will select all the
I am rewriting some old JavaScript with jQuery and would like to know how
I'm trying to write some javascript functions to integrate with the Facebook stream. However
I'm trying to write some javascript in an environment where square brackets are used
I am trying to write some javascript to allow me to click on a
So I'm trying to write some code to hide a piece of javascript 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.