Solved

Coldfusion - show or hide bootstrap modal

Posted on 2015-02-04
4
250 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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)

747 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

10 Experts available now in Live!

Get 1:1 Help Now