View Full Version : Floating Bar Javascript: Only display once per visitor

11-27-2008, 04:23 AM
RE: http://www.dynamicdrive.com/dynamicindex17/floatbar.htm

First of all, thank you so much for providing these great scripts for us all to use.

I just started using the floatbar script and it's working great. I was just wondering if there were some way to prevent the box from reappearing to the same visitor after they've clicked the "close" button but later revisit or reload the page, possibly by using their IP address or a cookie.

Also, if I add "position: center;" in the style section, the script will not work. Is there a way we can align the div bar to display in the middle of the page? If you use the x offset, it may not align properly if the window is sized differently.

Thanks again.

11-27-2008, 06:07 AM
Set persistclose to 1 in the script as shown below:

* Floating Top Bar script- Dynamic Drive (www.dynamicdrive.com)
* Sliding routine by Roy Whittle (http://www.javascript-fx.com/)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code

var persistclose=1 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
var startX = 30 //set x offset of bar in pixels
var startY = 5 //set y offset of bar in pixels
var verticalpos="fromtop" //enter "fromtop" or "frombottom"

To center the bar, set its left to 50%, and its margin left to a negative value half it's width. The !important directive should be used with the left property, ex:

border: 1px solid black;
padding: 2px;
background-color: lightyellow;
width: 620px;
left: 50%!important;
margin-left: -310px;
visibility: hidden;
z-index: 100;

11-27-2008, 03:18 PM
Thanks a ton! Worked like a charm.