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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:36:35+00:00 2026-05-27T00:36:35+00:00

I am using a JavaScript that reads the URL and parses the parameters. The

  • 0

I am using a JavaScript that reads the URL and parses the parameters. The JavaScript works just fine when I add a document.write to the body of the page. I am trying to take a parameter value and populate it into a Google JavaScript for ad serving. It would be ideal to take the parameter ‘fire’ from the ‘frank’ variable and replace it with ‘VALUE’ located in this JS: GA_googleAddAttr("ad_key", "VALUE");.

I feel as though I am missing something taking the result from the first JS and making it available for placement in the Google JS.

Any help will be greatly appreciated. Thank in advance.

Example URL: http://www.example.com/test.html?frank=fire

———— JavaScript: get url parameter ————

<script type="text/javascript">

function gup( name ){
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )    return "";
else    return results[1];}

var frank_param = gup( 'frank' );

</script>

———— JavaScript: google ad serving attribute ————

<script type="text/javascript">
GA_googleAddAttr("ad_key", "VALUE");
</script>

ad_key = Added within the Google DFP ad serving platform

VALUE = Used for targeting ads for a specific page


  • 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-27T00:36:35+00:00Added an answer on May 27, 2026 at 12:36 am

    The first script does a bunch of unnecessary work and is subtly incorrect.

    It will fail

    1. when the parameter name contains a back slash
    2. when there is no parameter in the query but there is one in the fragment
    3. when the parameter value contains a %-encoded character

    You can replace it with

    function gup(name) {
      var params = {};
      var parts = (window.location.search || '').split(/[&?]/);
      for (var i = 0; i < parts.length; ++i) {
        var eq = parts[i].indexOf('=');
        if (eq < 0) continue;
        params[decodeURIComponent(parts[i].substring(0, eq))]
            = decodeURIComponent(parts[i].substring(eq+1));
      }
      return Object.hasOwnProperty.call(params, name)
          ? params[name] : null;
    }
    

    which will correctly get you a CGI parameter value.

    Then just follow it with

    GA_googleAddAttr("ad_key", gup('frank') || '');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you safely encode a URL using JavaScript such that it can be
How can you preload an entire web page using JavaScript so that I can
I have a view using a master page that contains some javascript that needs
I am validating a zip code using Javascript that is generated server-side, and injected
Using JavaScript, how do I create an HTML table that can "accept" numeric matrix
I am using a charting javascript library that expects its data in a specific
I have some javascript that I'm trying to retool using jQuery to learn the
I am developing some client side Javascript that is using some JSON web services
I've been using Javascript's Date for a project, but noticed today that my code
I'm busy writing a application that refreshes a IFrame completely using javascript, now my

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.