LukevdPalen
4/11/2014 - 9:36 AM

AS2 form variables in start query string

AS2 form variables in start query string

//dit object bevat de form variablen
var vars:Object = new Object()

vars.date = '16-12-1986',
vars.verzerkering = 'ja'

var fallbackUrl = 'http://nu.nl?utm=lalalal';
var _clickTag = _root.clickTag || _root.ClickTag || _root.Clicktag || _root.Clicktag || fallbackUrl

function refactorClickTag(clickTag, variableObject) {
    // get base url
    var baseUrl = clickTag,
        secundairyQueryArr = [],
        primaryQueryArr = [];

    // Has a question mark in the url
    if (clickTag.indexOf('?') >= 0) {
        baseUrl = clickTag.split('?')[0];
        secundairyQueryArr = clickTag.split('?')[1].split('&');
    }

    for (var key in variableObject) {
        var value = variableObject[key];
        if (variableObject.hasOwnProperty(key)) {
            primaryQueryArr.push(key +'='+ value);
        }
    }
    var queryArr = primaryQueryArr.concat(secundairyQueryArr);

    return queryArr.length > 0 ? baseUrl +'?'+ queryArr.join('&') : baseUrl;
}

//getUrl(refactorClickTag(_clickTag, vars), '_blank');