Pregunta

So I'm more the designer then an advanced programmer. I know HTML and CSS very well but when I get into JavaScript things start confusing me. I need to see it in my head. Anyway...

I basically need a popup on site entry that will place a cookie so it will not be shown again. Basically what I need is this: http://www.vikin.net/index2.html

I took that from another site. The problem is that there is so much extra code in there for form validation that isn't needed. So I was wondering if someone could help me get the same effect in the simplest form. This is the second or third time someone has asked me for this exact same thing and I just don't like what I find when I Google it.

¿Fue útil?

Solución

First of all, since you are new to the site I hope people will cut you some slack, but you have got to learn how to post a question here properly. It starts with showing what you have attempted by posting some code.

To help you out, start by searching the source code you are trying to modify for the terms you're looking for, e.g. "cookie". Here's what I found in mainPopup.js. Copy this into a separate script and start building from it. When you have a specific problem with specific code you've tried come back and someone will help you out. And use jsfiddle.net for javascript questions!

//Cookie functions for having the popup only display after a given interval

function setCookie(c_name, value, exdays) {

    var exdate = new Date();

    exdate.setDate(exdate.getDate() + exdays);

    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString() + "; path=/");

    document.cookie = c_name + "=" + c_value;

}

function getCookie(c_name) {

    var i, x, y, ARRcookies = document.cookie.split(";");

    for (i = 0; i < ARRcookies.length; i++) {

        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));

        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);

        x = x.replace(/^\s+|\s+$/g, "");

        if (x == c_name) {

            return unescape(y);

        }
    }

    return null;

}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top