Once again, brothers and sisters, let us delve into the eldrich, occult world of ... programming.
Or to put it another way - let's make your landers even more effective.
In this, the final part (for now) of my basic introduction to programming for affiliates, we're going to look at making your landing pages change and react based on what your visitors do.
We'll cover how to change parts of the page based on where they click; look at how your outsourced programmers might have done this on landers you already have (so that you can easily change them); look at timing-based changes; and even touch on animation!
Let's get going!
What You'll Need For This Tutorial
If you haven't read them already, Part 1 and Part 2 of this course are here and here, respectively. We won't be using code from those two parts, but we will be using the concepts in them. If you get stuck here, there's a good chance that having a look through those earlier parts will unstick you.
Other than that, you don't need to know any Javascript, just HTML and CSS.
You can easily apply the techniques I'll show you here to your existing landers, and that's probably the best way to learn. However, if you want a sample lander to experiment with, here's the code for a simple tester to use whilst you're learning:
<head> <title>Parameter Passing Test</title> </head> <body> <div id="question"><h1>Do You Like Money?</h1> <button id="yes">Yes</button> </div> <div id="answer" style="display:none"><h1>You're In Luck, Then!</h1> <p><a href="http://www.motleyfool.com">So Do These Guys!</a> </div> </body>

document.getElementById('question').style.display = "none" ;
document.getElementById('answer').style.display = "block" ;
function showhide(){
document.getElementById('question').style.display = "none" ;
document.getElementById('answer').style.display = "block" ;
}

function showhide(showthis, hidethis){
document.getElementById(hidethis).style.display = "none" ;
document.getElementById(showthis).style.display = "block" ;
}
function bigbutton(){
document.getElementById("yes").style.fontSize = "xx-large";
}
It's just a quirk you need to remember.function countdown(){
document.getElementById("countdown").innerHTML = document.getElementById("countdown").innerHTML - 1;
}
<style>
#yes {
-webkit-transition: all 1s;
-moz-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
}
</style>
This is awesome! Thank you for taking your time out to put all these tutorial together. I'm a noob and was really struggling with understanding all these codes! This really helped me a lot.
@ekentran1558 - No problem!
awesome tutorial caurmen!
Hi Caurmen,
I've been trying to figure this out for a bit now and was wondering if you could help. I've tried other things but haven't been successful with the codes for the methods that I have in mind.
Here's the code:
<div class="clear"></div>
<div><a target="_top" class="button5" href="http://
</div>
What i'm trying to do here is have an alert message pop up, the user press ok, the user is then redirected to my offer page. Please advise.
-Ken
You'll need to make some changes to the second line to make that work.
Here's the corrected version:
<div><a target="_top" class="button5" href="http://Voluum.com /click" onclick="alert('message'); window.location.href = 'http://www.google.com';">SELECT</a></div>
That really clears it up. I'm in my second month and wanting to hit 100 mph with a bunch of ideas only to keep getting lost. haha
Thank you so much!
Hi Caurmen,
I have a few more questions that I'm a little confused with.
So I got the alert script working on the lp when the user select the offer. However, when trying to add an exit pop at the very end, both the alert message and the exit pop appears one after another.
Here's my code:
<script language="javascript">var PreventExitPop = true;function ExitPop() {if(PreventExitPop != false) {return "message!"}}window.onbeforeunload = ExitPop;</script>
First the the user select the offer, the alert message would pop up. Which is expected, but the the exit pop also pops up after that before going to the offer.
Another issue that I am trying to figure out is an exit pop with redirect. Here's the code I found from google is this:
<script language="javascript">
(function() {
setTimeout(function() {
var __redirect_to = 'http://google.com';//
var _tags = ['button', 'input', 'a'], _els, _i, _i2;
for(_i in _tags) {
_els = document.getElementsByTagName(_tags[_i]);
for(_i2 in _els) {
if((_tags[_i] == 'input' && _els[_i2].type != 'button' && _els[_i2].type != 'submit' && _els[_i2].type != 'image') || _els[_i2].target == '_blank') continue;
_els[_i2].onclick = function() {window.onbeforeunload = function(){};}
}
}
window.onbeforeunload = function() {
setTimeout(function() {
window.onbeforeunload = function() {};
setTimeout(function() {
document.location.href = __redirect_to;
}, 500);
},5);
return 'message';
}
}, 500);
})();
The problem when using this code is that it disable the "alert(" code. Also, sometimes it works and sometimes redirect works but sometimes it doesn't.
It looks more complicated than I thought.
Here are my questions;
1. How can I make the alert and the exit pop work on the same lander without any interference from one another?
For the first scenario: If the offer were selected, only the alert would come up. If the user exits or hit the back button, only the exit pop would come up.
2. Is there a simpler code or way for me to code what I'm trying to do in the second scenario?
My first thought was two separate code. The first was the exit pop follow by the back button redirect but that didn't work.
Please advise.
Thanks for the guides!
Quick question: For the javascript based timer, how do you set it so that the timer stops at 0?
Because right now, the counter keeps counting down from 0, -1, -2, -3 till infinite
Edit: I found the answer on stackoverflow, and it's working for me!
http://stackoverflow.com/questions/1...t-reaches-to-0
<span id="counter">5</div>
<script type="text/javascript">
function countdown() {
var i = document.getElementById('counter');
i.innerHTML = parseInt(i.innerHTML)-1;
if (parseInt(i.innerHTML)==0) {
clearInterval(timerId);
}
}
var timerId = setInterval(function(){ countdown(); },1000);
</script>
Hello Caurman
I ripped a lander and found a piece of javascript that I don't know what it can do, so could you please explain it briefly? Thanks!
I guess that it do a redirect job, am I right? If I delete it, will the lander work well?
<script>
;;
(function($) {
if (!$.browser && 1.9 <= parseFloat($.fn.jquery)) {
var a = {
browser: void 0,
version: void 0,
mobile: !1
};
navigator && navigator.userAgent && (a.ua = navigator.userAgent, a.webkit = /WebKit/i.test(a.ua), a.browserArray = "MSIE Chrome Opera Kindle Silk BlackBerry PlayBook Android Safari Mozilla Nokia".split(" "), /Sony[^ ]*/i.test(a.ua) ? a.mobile = "Sony" : /RIM Tablet/i.test(a.ua) ? a.mobile = "RIM Tablet" : /BlackBerry/i.test(a.ua) ? a.mobile = "BlackBerry" : /iPhone/i.test(a.ua) ? a.mobile = "iPhone" : /iPad/i.test(a.ua) ? a.mobile = "iPad" : /iPod/i.test(a.ua) ? a.mobile = "iPod" : /Opera Mini/i.test(a.ua) ? a.mobile = "Opera Mini" : /IEMobile/i.test(a.ua) ? a.mobile = "IEMobile" : /BB[0-9]{1,}; Touch/i.test(a.ua) ? a.mobile = "BlackBerry" : /Nokia/i.test(a.ua) ? a.mobile = "Nokia" : /Android/i.test(a.ua) && (a.mobile = "Android"), /MSIE|Trident/i.test(a.ua) ? (a.browser = "MSIE", a.version = /MSIE/i.test(navigator.userAgent) && 0 < parseFloat(a.ua.split("MSIE")[1].replace(/[^0-9\.]/g, "")) ? parseFloat(a.ua.split("MSIE")[1].replace(/[^0-9\.]/g, "")) : "Edge", /Trident/i.test(a.ua) && /rv
[0-9]{1,}[\.0-9]{0,})/.test(a.ua) && (a.version = parseFloat(a.ua.match(/rv
[0-9]{1,}[\.0-9]{0,})/)[1].replace(/[^0-9\.]/g, "")))) : /Chrome/.test(a.ua) ? (a.browser = "Chrome", a.version = parseFloat(a.ua.split("Chrome/")[1].split("Safari")[0].replace(/[^0-9\.]/g, ""))) : /Opera/.test(a.ua) ? (a.browser = "Opera", a.version = parseFloat(a.ua.split("Version/")[1].replace(/[^0-9\.]/g, ""))) : /Kindle|Silk|KFTT|KFOT|KFJWA|KFJWI|KFSOWI|KFTHWA|KF THWI|KFAPWA|KFAPWI/i.test(a.ua) ? (a.mobile = "Kindle", /Silk/i.test(a.ua) ? (a.browser = "Silk", a.version = parseFloat(a.ua.split("Silk/")[1].split("Safari")[0].replace(/[^0-9\.]/g, ""))) : /Kindle/i.test(a.ua) && /Version/i.test(a.ua) && (a.browser = "Kindle", a.version = parseFloat(a.ua.split("Version/")[1].split("Safari")[0].replace(/[^0-9\.]/g, "")))) : /BlackBerry/.test(a.ua) ? (a.browser = "BlackBerry", a.version = parseFloat(a.ua.split("/")[1].replace(/[^0-9\.]/g, ""))) : /PlayBook/.test(a.ua) ? (a.browser = "PlayBook", a.version = parseFloat(a.ua.split("Version/")[1].split("Safari")[0].replace(/[^0-9\.]/g, ""))) : /BB[0-9]{1,}; Touch/.test(a.ua) ? (a.browser = "Blackberry", a.version = parseFloat(a.ua.split("Version/")[1].split("Safari")[0].replace(/[^0-9\.]/g, ""))) : /Android/.test(a.ua) ? (a.browser = "Android", a.version = parseFloat(a.ua.split("Version/")[1].split("Safari")[0].replace(/[^0-9\.]/g, ""))) : /Safari/.test(a.ua) ? (a.browser = "Safari", a.version = parseFloat(a.ua.split("Version/")[1].split("Safari")[0].replace(/[^0-9\.]/g, ""))) : /Firefox/.test(a.ua) ? (a.browser = "Mozilla", a.version = parseFloat(a.ua.split("Firefox/")[1].replace(/[^0-9\.]/g, ""))) : /Nokia/.test(a.ua) && (a.browser = "Nokia", a.version = parseFloat(a.ua.split("Browser")[1].replace(/[^0-9\.]/g, ""))));
if (a.browser)
for (var b in a.browserArray) a[a.browserArray[b].toLowerCase()] = a.browser == a.browserArray[b];
$.extend(!0, $.browser = {}, a)
}
})(jQuery);
(function() {
(function() {
$.browser.webkit || $.event.add(window, "load", function() {
$("a[href][rel~=noreferrer], area[href][rel~=noreferrer]").each(function() {
var b, e, c, g, d, f, h;
b = this;
c = b.href;
$.browser.opera ? (b.href = "http://www.google.com/url?q=" + encodeURIComponent(c), b.title || (b.title = "Go to " + c)) : (d = !1, g = function() {
b.href = "javascript:void(0)"
}, f = function() {
b.href = c
}, $(b).bind("mouseout mouseover focus blur", f).mousedown(function(a) {
a.which === 2 && (d = !0)
}).blur(function() {
d = !1
}).mouseup(function(a) {
if (!(a.which ===
2 && d)) return !0;
g();
d = !1;
setTimeout(function() {
f()
}, 500);
return !1
}), e = "<html><head><meta http-equiv='Refresh' content='0; URL=http://domainname/"+$("<p/>"
.text(c).html()+"' /></head><body></body></html>", $.browser.msie ? $(b).click(function() {
var a;
switch (a = this.target || "_self") {
case "_self":
case window.name:
a = window;
break;
default:
a = window.open(null, a)
}
a = a.document;
a.clear();
a.write(e);
a.close();
return !1
}) : (h = "data:text/html;charset=utf-8," +
encodeURIComponent(e), $(b).click(function() {
this.href = h;
return !0
})))
})
})
})()
}).call(this);
</script>
Hmm, that's pretty complex. On a quick look - not a full code audit - it looks to be doing something significantly more complex than a simple redirect.
It's detecting the useragent then performing different things based on which browser is detected. Looking at the code, there's a good chance that it's deliberately obfuscating what it's doing too, although I'm not certain on that. (The very short variable names and multiple reassignments are what make me think there might be something fishy going on.)
It could also be that this Javascript depends on other scripts loaded on the page - were there other scripts loaded or included in the lander?
I'd be wary of running a lander with this code intact. However, there's a good chance that removing it will break some of the page's functionality.
It's very hard to say more on what the code does without it being properly formatted (so that it's easier to see where the code blocks start, end and indent), and without putting quite a lot of time into it.
(I also checked this with a very high-level senior developer friend of mine, and his opinion is the same as mine - obfuscated code, hard to tell what it does without reformatting it. Probably best to avoid running it on your landers.)
Thanks caurmen.
I am really appreciated that you took your time to check this code.
I have deleted some pieces of JavaScript with obfuscated code that I don't know at all, and the lander works properly. After reading all your threads about JavaScript I can understand some easy scripts and clean the landers I ripped. Your tutorial is clear and newbie friendly.
Awesome.
Cool, glad it helped!
Pro tip given that lander looked like it had some obfuscation going on: check the CSS for scripts too. Most people don't know this but there are ways to embed Javascript in CSS as well.
This is gold!
I've been doing the Codecademy JS course and I'm constantly worrying whether some of the things im learning are useful for AM or not. These series show me how they can be applied to AM - so so soooo helpful!
Please keep it going 
@thetailend - Being able to program is a major unfair advantage as an affiliate. Use it ruthlessly! 