Coldfusion - show or hide bootstrap modal

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.
Bang-O-MaticAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
gdemariaConnect With a Mentor Commented:
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
 
gdemariaCommented:
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
 
Bang-O-MaticAuthor Commented:
Hi gdemaria,

Could you give me a code example to work from?

Thanks for the help!
0
 
Bang-O-MaticAuthor Commented:
Thanks gdemaria! that worked out great.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.