Magento Expert Forum - Improve your Magento experience

Results 1 to 6 of 6

How to Popup before homepage appears

  1. #1
    New member
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to Popup before homepage appears

    Please tell me how can I Make popup window appear before the index page opens having a simple email submission and one liner with a logo, users must have an option for close button no captcha is required only an @ i.e valid email check is required.

    The box should not appear again (cookies must be checked).

    No duplicate checks are required

    I want to store the submitted emails to be stored in a text file in comma seperated value.

    Kindly help me out.

    Thanks in advance.

    View more threads in the same category:


  2. #2
    Administrator david's Avatar
    Join Date
    Nov 2012
    Posts
    261
    Thanks
    22
    Thanked 42 Times in 34 Posts

    Default

    Instead of using hook in magento, you can simply add the code in index.php file and catch the cookie to display the welcome page before loading magento.

  3. #3
    New member
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I tried that but its not working

    Quote Originally Posted by david View Post
    Instead of using hook in magento, you can simply add the code in index.php file and catch the cookie to display the welcome page before loading magento.

    I tried a php code in the homepage but entire page was unable to load.

    I am new to magento as well as coding. It would be very nice if you can give me an example please. like where to keep the text file where to add the code and how do i configure the cookie thing.

  4. #4
    Administrator david's Avatar
    Join Date
    Nov 2012
    Posts
    261
    Thanks
    22
    Thanked 42 Times in 34 Posts

    Default

    Sorry to reply you late. Here is some simple code for it. Put it before of any code line in index.php of magento

    Code:
    if(!isset($_COOKIE['welcome_page']){ 
        setcookie("welcome_page", $value, time()+3600);  /* expire in 1 hour or unlimited if you need */
        include 'welcomepage.php';die; /* include welcome page and stop */
    } // else do nothing

  5. #5
    New member
    Join Date
    Dec 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks david

    Quote Originally Posted by david View Post
    Sorry to reply you late. Here is some simple code for it. Put it before of any code line in index.php of magento

    Code:
    if(!isset($_COOKIE['welcome_page']){ 
        setcookie("welcome_page", $value, time()+3600);  /* expire in 1 hour or unlimited if you need */
        include 'welcomepage.php';die; /* include welcome page and stop */
    } // else do nothing

    David I knew would reply but where is the code for the popup that would :
    1.request user to enter email with a submit button (with a validation check if entered email is in correct format or not)
    2.then that submitted email would be written to a txt file separated by comma.
    3. user would have the option of closing the popup without submitting or submitting duplicates

    in your reply I didn't get what do you mean by welcomepage.php and I do not have any index.php

    I see my main page is noname.phtml and the page is deep within the root ....../design/frontend/nonamelphtml

    now here is the cookie that is generated by JS

    if (!window.Mage) var Mage = {};

    Mage.Cookies = {};
    Mage.Cookies.expires = null;
    Mage.Cookies.path = '/';
    Mage.Cookies.domain = null;
    Mage.Cookies.secure = false;
    Mage.Cookies.set = function(name, value){
    var argv = arguments;
    var argc = arguments.length;
    var expires = (argc > 2) ? argv[2] : Mage.Cookies.expires;
    var path = (argc > 3) ? argv[3] : Mage.Cookies.path;
    var domain = (argc > 4) ? argv[4] : Mage.Cookies.domain;
    var secure = (argc > 5) ? argv[5] : Mage.Cookies.secure;
    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
    };

    Mage.Cookies.get = function(name){
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    var j = 0;
    while(i < clen){
    j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return Mage.Cookies.getCookieVal(j);
    i = document.cookie.indexOf(" ", i) + 1;
    if(i == 0)
    break;
    }
    return null;
    };

    Mage.Cookies.clear = function(name) {
    if(Mage.Cookies.get(name)){
    document.cookie = name + "=" +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
    };

    Mage.Cookies.getCookieVal = function(offset){
    var endstr = document.cookie.indexOf(";", offset);
    if(endstr == -1){
    endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));



    Please reply as soon as possible
    Thank you

  6. #6
    Administrator david's Avatar
    Join Date
    Nov 2012
    Posts
    261
    Thanks
    22
    Thanked 42 Times in 34 Posts

    Default

    Well, I see you make it too complicate. Let 's make it simple. This shouldn't relate to any major magento coding. It is simply a PHP coding with welcomepage.php is the JS popup code. We shouldn't use cookie check by JS in this case. Or if you really want to use JS you should use jQuery cookie plugin instead of pure JS. Please feel free to let me know if you have any more problem to implement your solution.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •