Can we use first and third party cookies and web beacons to understand our audience, and to tailor promotions you see?

ThickBox onLoad for Login and Nag etc..

------------------------------- I am trying to run the ThickBox Window only the first time they enter the page as a login and nag page. I have been at this for literally days used different methods such as trying to jerry rig drupal to use both jquery and prototype etc... I think this is the closet I have gotten. My problem it tells me my url is not an image?? my url is going to a login page that was custom made .tpl.php login (I altered the Template.php to look for /login for only one case not for all other logins etc.. for drupal just need to be able to load it in the iframe........ any ideas I am starting to go blind.. The above javascript does work and understands not to run the code if they have already been to the page... Your help will be greatly appreciated thanks and may the force be with you.......................

<script>
window.onload = checkVisit;

function setCookie(name, value, expires, path, domain, secure) {
document.cookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}

function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1) {
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
}

function checkVisit() {
// Check last viewed version
var cookie = getCookie("javawin");
if (cookie == null || parseFloat(cookie) < 1.2) {

ShowThickbox();

date=new Date;
date.setMonth(date.getMonth()+3);
setCookie("javawin", "1.2", date);

}
}

function ShowThickbox()
{
TB_show('Thickbox Title', '/xampp/I-Create/?q=user/login?KeepThis=true&TB_iframe=true&height=400&width=600', null);
}
</script>

Comments

mounte’s picture

Possible solution?
I wanted something like what you want.
If user not loged on ==> display Nag/Login
If user loged on ==> display page
I made this little addition to the page.tpl.php in the header below where the scripts are included I added

<?php
	global $user;
	if(!$user->uid) {
print('	<script>
		window.onload = loadLoginNag;
		function loadLoginNag() {
			TB_show("Please, login", "?TB_inline=true&inlineId=Hidden_Login&height=180&width=300&modal=true", null);
		}
		</script>');
}
?>

And in the Body I added the following:

<?php
global $user;
if(!$user->uid) {
	print('
	<div id="Hidden_Login" style="display:none">
		<form id="user-login" method="post" action="/drupal/?q=user/login&destination=mysite">
		<div>
		<div class="form-item">
		<label for="edit-name">
		Username:
		<span class="form-required" title="This field is required.">*</span>
		</label>
		<input id="edit-name" class="form-text required" type="text" tabindex="1" value="" size="25" name="name" maxlength="60"/>
		<div class="description">Enter your TATnet 07 summer edition username.</div>
		</div>
		<div class="form-item">
		<label for="edit-pass">
		Password:
		<span class="form-required" title="This field is required.">*</span>
		</label>
		<input id="edit-pass" class="form-text required" type="password" tabindex="2" size="25" name="pass"/>
		<div class="description">Enter the password that accompanies your username.</div>
		</div>
		<input id="edit-user-login" type="hidden" value="user_login" name="form_id"/>
		<input id="edit-submit" class="form-submit" type="submit" tabindex="3" value="Log in" name="op"/>
		</div>
		</form>
	</div> ');
}
?>

Hope that it might help you
//
Daniel

sol1313’s picture

I have been breaking my head for hours on this and I was able to create a pop up box on the first time visit based on the code above. Here's what I did in case someone needs it.

Code for displaying a first time visitor window in thickbox
I put this in the head tag

<?php //This goes in the header
$cookie = $_COOKIE['new']; //If the cookie is there it'll get the value.
if($cookie == 1){ //do nothing, cookie is set.

}else{ //cookie not set, show login prompt box
  ?>
   <script>
        window.onload = loadLoginNag;
        function loadLoginNag() {
            tb_show("Welcome!", "?TB_inline=true&inlineId=hiddenModalContent&height=180&width=300", null);
        }
    </script>
  <?php 
    setcookie("new",1,time()+60*60*24*365);}
//Sets the cookie to the name new, value 1, and it'll expire after 1 year.
?> 

Then, in the body I have the div to display:

   <div id="hiddenModalContent" style="display:none;">
			<h2 class="title block-title pngfix">First time visitor?</h2><p>Welcome to the new CABA Online site. In order to access all our new features, <br/>please <a href="http://soldesigns.net/caba/user/register">CLICK HERE</a> to create a new account.</p></div>

Hope this helps someone else! Pay it forward!

Sol

sramsamy’s picture

Hi Sol.

You are a genius! Thanks for the code above. I have one issue i.e it works great on my PC (localhost) but when i do same on my http server it shows up the popup each time.

Here's my code:

/**
 * @package WordPress
 * @subpackage Default_Theme
 */
$cookie = $_COOKIE['new']; //If the cookie is there it'll get the value.
if($cookie == 1){ //do nothing, cookie is set.

}else{ //cookie not set, show login prompt box
  
function showThickbox() { $(document).ready(function() { tb_show('','register.html'+'?KeepThis=true&TB_iframe=true&height=304&width=300&','modal=true',false); }); }
    setcookie("new",1,time()+60*60*24*365);}
//Sets the cookie to the name new, value 1, and it'll expire after 1 year.

get_header(); 
function readCookie(name) { var nameEQ = name + “=”; var ca = document.cookie.split(‘;’); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==’ ‘) c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } } }

-----------------------------

Thanks a lot if you know a solution to my problem

sol1313’s picture

Here's the same code to detect the browser version and display a link to upgrade.

I added this code in the body tag:

<div id="warning"><p>This site is best viewed with Internet Explorer 7, Firefox 3 or Safari 4. Please upgrade your browser in order to view the site properly. <br/><a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=9AE91EBE-3385-447C-8A30-081805B2F90B&displaylang=en" target="new">Click Here to download the latest version of Internet Explorer.</a></p></div>
    <script>
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
//alert(browser+' '+b_version);
if ((browser=="Netscape"||browser=="Microsoft Internet Explorer")
  && (version>=4))
{
       //do nothing, browser is minimum acceptable version
}
else
{
    //show pop up with link to upgrade browser
    tb_show("Older Browser Detected", "?TB_inline=true&inlineId=warning&height=300&width=300", null);
}
</script>

Hope it helps!
Sol

venusrising’s picture

Thanks so much for this I have been going crazy! Ahhhh. One question, is there any way to theme this so it matches the TB (standard TB CSS) on my site? I tried to add the div id of TB_window but it does not work

Cheers!

venusrising