Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Dynamic Meta Tags via URL Variables

If you're able to help with this problem, I'd appreciate it as I'm out of my depth.

I have a bunch of meta tags in a HTML header that need to map their content to variables in the URL. For example, if we have this URL:

http://example.com?bofn=Dave&boln=Nate&boem=Pat&botn=Taylor&bstn=Chris&lstn=Rami

We would want the meta tags in the header to read as this:

<meta name="bofn" content="Dave">
<meta name="boln" content="Nate">
<meta name="boem" content="Pat">
<meta name="botn" content="Taylor">
<meta name="bstn" content="Chris">
<meta name="lstn" content="Rami">

From what I've found online this would probably use javascript to function (URLSearchParams and/or location.search?) but I've no clue how to make it happen.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Split URL string into variables and its values, than go through them and create for each one new meta element.

var str = 'http:example.com?bofn=Dave&boln=Nate&boem=Pat&botn=Taylor&bstn=Chris&lstn=Rami';

// split('?')[1] takes all after '?' (removes http://example.com)
// split('&') creates array ('bofn=Dave', 'boln=Nate', ...)
var parts = str.split('?')[1].split('&');

// go through all variables
for (let i = 0; i < parts.length; i++) {
    // create new HTML element
    var el = document.createElement('meta');
   
    // split key, value
    var keyval = parts[i].split('=');

    // set name and content attributes, fill values in
    el.name = keyval[0];
    el.content = keyval[1];
    
    // append meta elements to head
    document.getElementsByTagName('head')[0].appendChild(el);
}

about 4 years ago · Juan Pablo Isaza Report

0

I was able to solve the issue with Pavel's help by replacing the URL with window.location.href:

<script>
var str = window.location.href;

// split('?')[1] takes all after '?' (removes http://example.com)
// split('&') creates array ('bofn=Dave', 'boln=Nate', ...)
var parts = str.split('?')[1].split('&');

// go through all variables
for (let i = 0; i < parts.length; i++) {
    // create new HTML element
    var el = document.createElement('meta');
   
    // split key, value
    var keyval = parts[i].split('=');

    // set name and content attributes, fill values in
    el.name = keyval[0];
    el.content = keyval[1];
    
    // append meta elements to head
    document.getElementsByTagName('head')[0].appendChild(el);
}
</script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!