mardi 27 mars 2018

Using URL parameters to place content into a div?

I'm working on a opt in page. I would like the user's current subscription data to display at the top of the page. My method is placing content into a div based on URL parameters. If the parameter does not exist I want it to drop into a different div. See code below:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"> 
var testSub = '<span>Subscription data</span>';
if (/testnews=1/.test(window.location.href)) {
    document.getElementById('subscribed').innerHTML=testSub; 
}
else { 
    document.getElementById('not_subscribed').innerHTML=testSub; 
}
</script>
</head>
<body>
<div id="subscribed"></div>
<div id="not_subscribed"></div>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire