Solved

Coldfusion - show or hide bootstrap modal

Posted on 2015-02-04
4
255 Views
Last Modified: 2016-02-25
I want to show a "register" modal window on my site after  a certain number of page views lets say 3 page views.

Currently, I have the "register" modal setup to be shown at page load unless the user is loggedin, in which case the modal will not be shown.

What I need help with is how to delay showing the "register" modal until the user has viewed more than 3 pages?

Thanks.
0
Comment
Question by:Bang-O-Matic
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 40589068
Why not use a session variable to count the page views (only count if the user is not logged in), then when you get to count 3, you can set the display to visible.   In fact, you don't even need the code to be on the page before the third page view... so just include the code on page view 3
0
 

Author Comment

by:Bang-O-Matic
ID: 40589202
Hi gdemaria,

Could you give me a code example to work from?

Thanks for the help!
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 40589253
These two lines of code in your application.cfm / .cfc file will count the number of page views for that user's session

<cfparam name="session.PageCount" default="0">   <!--- this will create a session variable if it does not exist  --->

<cfset session.pageCount = val(session.pageCount) + 1>  <!--- increment the page count ---->


Then on your page, you can test to see if the number is 3 and in this case, I am showing how you can test for page view 3 or page view 10 or any other.

<cfif val(session.pageCount) eq 3 or val(session.pageCount) eq 10>

    (Put your code here to display the thing you want to display)

</cfif>


Since you also wanted to be sure the user was not logged in, you need to add a test for that..

<cfif NOT val(session.user_id) and val(session.pageCount) eq 3 or val(session.pageCount) eq 10>

    (Put your code here to display the thing you want to display)

</cfif>
0
 

Author Closing Comment

by:Bang-O-Matic
ID: 40589420
Thanks gdemaria! that worked out great.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now