Solved

Coldfusion - show or hide bootstrap modal

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

828 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