How to Display Dynamic Content on a Page Using URL Parameters

In:

In this tutorial, I will show you how to show/hide dynamic content based on URL parameters for any web page. This solution uses HTML, CSS and JavaScript instead of backend coding, so you will be able to use it with Marketo, Pardot, or any other system that allows a bit of custom code.

The HTML

Wrap each one of your dynamic content sections in a DIV and add a class called dynamic-content. Also, give each DIV a unique ID. We will reference these later in the JavaScript.

The CSS

There’s only one line of CSS needed to hide all the elements on the page since JavaScript will be used to show/hide the content.

The JavaScript

This is the complicated part. First, we need to parse the URL and check for a specific parameter. For this example I will be using the parameter name “dc”, so in this case, my URL would look like this:

https://jennamolby.com/my-webpage?dc=mycontent

This is the piece of code to parse the URL. You can change “dc” to be whatever parameter name you want.

Use jQuery to show/hide content

To make things easier, we’ll use jQuery to show/hide the content, in conjuction with the javascript. You can add in as many conditions as you want, just make sure you always include default content just in case parameters are misspelled or not in the URL.

The full javaScript code

Here’s the full piece of javascript and jQuery code.

Questions?

Email me, send me a tweet @jennamolby, or leave a comment

Related Posts

  • 25/07/2018
    2 Free Pardot Landing Page Templates You Can Use for Your Next Event

    Create beautiful, responsive landing pages in Pardot by using one of these 2 free Pardot layout templates. These landing page templates are designed specifically for events such as webinars or trade shows, but they will work well with any landing page that contains a form.

  • 18/07/2018
    The Best Way to Create a 2 Column Pardot Form

    In this tutorial, I’ll show you the best way to create a two-column Pardot form. This is a follow up on my original post How to Create a 2 Column Pardot Form. By popular request, this new method includes a way to make certain form fields full width. All you have to do is add CSS classes to your form fields and copy & paste the CSS provided into Pardot.

  • 11/07/2018
    How To Use UTM Parameters to Capture Lead Source in Pardot

    You might already be using UTM parameters to track your marketing campaigns with Google Analytics, but are you capturing that information when a prospect is created in Pardot? Capturing this data is critical in order to assess the value of your marketing campaign and is a lead management best practice.

About Me

Welcome to my blog, where I share, tips, tricks, thoughts and solutions that I learn in my daily life as a sales and marketing professional.

LEARN MORE

Categories
Most Commented
Popular Posts