Rich-text Reply

Dynamic content via query string

donaldduck 05-16-16

Dynamic content via query string

[ Edited ]

Is it possible to add dynamic content to a landing page.  Can the content be passed in via a querty string?

MartijnSch 05-17-16
 

Re: Dynamic content via query string

Yes it can Donald, what you'll have to do is make sure to pick up the content from the parameter and create a variable out of it so you can paste it in the landing page by doing this. It's likely that you'll have to write some custom code for this in your variation to deal with this.
robertchan 05-24-16
 

Re: Dynamic content via query string

Hi @donaldduck, yes you can. Here's an example of adding content (you can paste it into your variation code):

 

/*jshint esnext: true */
/*jshint browser: true */

(() => {
  'use strict';
  const el = document.createElement('div'); // create a div
  document.body.appendChild(el); // append the div to your body
})();
Robert Chan

Experimentation Hero
CouchPsycho 06-02-16
 

Re: Dynamic content via query string

I use this function to extract params from the query string:

 

$.mrUrlParam = function(name)
{
    var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (results === null)
    {
       return false;
    }
    else
    {
       return results[1] || false;
    }
};

You can get the value of the param by this:

var paramValue = $.mrUrlParam("param");

Now you can add the value itself to the page or can use the value to use it in if- or switch-statements.




"the essence of the creative act is to see the familiar as strange." (anonymous)