Announcement

Collapse
No announcement yet.

Load javascript once per week, or otherwise avoid loading on every page load

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Load javascript once per week, or otherwise avoid loading on every page load

    Not sure if this is possible, and it is embarrassingly hackish, but I was thinking of using something like http://www.projectseven.com/products...tips/index.htm to generate a popup for something the boss wants. It generates all the code but does not have an option to maintain the state (cookies or some other way to avoid serving the popup on every load of the main page). I was wondering if there might be a way with Toolkit or some script to wrap the onload statement - or perhaps just switch visibility to hidden on the div - and control how often it shows that way. I was thinking of something simple like only showing it once every 7 days or similar. I don't want them to get annoyed at seeing it every time the go to the site.

    I'm not a javascript guy and even though I have used existing examples to do stuff on the site - including something very much like this some time back- I'm not comfortable just hacking examples I don't fully understand and slapping it in there and hoping there are no conflicts etc. I have used the PVII products for other stuff like slideshows and menus and they work well together, I can use it on multiple projects and the cost is a lot less than custom programming.
    Last edited by habreu; 01-07-15, 12:58 PM.

    #2
    Re: Load javascript once per week, or otherwise avoid loading on every page load

    Typically, this would use a Cookie.

    If no valid cookie exists, set cookie, show popup.

    In the set cookie function, set the expire date to seven days. Seven days later, the cookie test will return null since the cookie expired.
    Bruce Golub
    Phosphor Media - "Your Success is our Business"

    Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
    phosphormedia.com

    Comment


      #3
      Re: Load javascript once per week, or otherwise avoid loading on every page load

      Thanks Bruce. I'm tinkering with this now and will sort it out.

      Comment


        #4
        Re: Load javascript once per week, or otherwise avoid loading on every page load

        Here's a bit of SMT with Toolkit and a shadowbox script that checks if a visitor has previously been invited to take a survey and acts accordingly. A cookie is set saying they were invited (line 31) if it's not already there.

        Code:
        <!-- Begin Survey Invitation //-->
        <mvt:comment> Test for Survey Invitation Cookie </mvt:comment>
        <mvt:if expr="NOT g.secure">
        <mvt:comment> Test For Survey Cookie and Set Variable if it exists </mvt:comment>
        <mvt:item name="toolkit" param="vacreate|cookies|s.http_cookie|;" />
        <mvt:if expr="NOT ISNULL l.settings:cookies">
        <mvt:foreach iterator="cookie" array="cookies">
        <mvt:item name="toolkit" param="gettoken|l.all_settings:cookie,=,1|name" />
        <mvt:if expr="g.name EQ 'prusurvey'">
        <mvt:item name="toolkit" param="sassign|prusurvey|Yes" />
        </mvt:if>
        </mvt:foreach>
        </mvt:if>
        <mvt:comment> END: Cookie Test Code </mvt:comment>
        <mvt:comment> Test for psurvey Variable </mvt:comment>
        <mvt:if expr="NOT g.prusurvey">
        <script type="text/javascript">
        window.onload = function() {
        
            // open a welcome message as soon as the window loads
            Shadowbox.open({
                content:    'more-info/survey-invitation.htm',
                player:     "iframe",
                title:      "Tell Us About Your Visit",
                height:     500,
                width:      600
            });
        
        };
        </script>
        <mvt:item name="toolkit" param="setcookie|g.Screen|prusurvey|720|0" />
        <mvt:item name="toolkit" param="sassign|prusurvey|Yes" />
        </mvt:if>
        </mvt:if>
        <mvt:comment> END: Survey Invitation Code </mvt:comment>
        <!-- End Survey Invitation //-->
        Hope it helps.
        Last edited by nottheusual1; 01-08-15, 06:39 PM. Reason: Clarification

        Comment


          #5
          Re: Load javascript once per week, or otherwise avoid loading on every page load

          @nottheusual1 - thanks very much. I'll pick this apart if a few minutes.

          Comment

          Working...
          X