Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWebsite Development and Maintenance

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Display-Once Notice

A display-once notice is displayed once when the site visitor arrives at the website the first time. On page reloads and upon visiting other pages with the same browser, the notice doesn't display again.

Until the browser is closed and exited.

The cookie set with the display-once notice is a volatile cookie. When the browser is relaunched after being completely exited from memory, the cookie is no longer there.

This display-once notice was developed for the Willmaster website after the server move. PHP, MySQL, and Perl at the new server were all the latest versions. The latest version of PHP, especially, introduced code-breaking changes to the software we made for ourselves over the years.

A bit of wisdom gained:

Update to the latest stable version of important software when you can.

Waiting until suddenly it all needs to be done at once is not wise.

A notice was made for the website to alert site visitors that we are diligently working to fix all that broke. When the site visitor taps the "Dismiss" link, a cookie is set so the notice won't appear on subsequent page loads.

For a short while, the willmaster.com website itself is a live example of how the display-once notice works.

This article describes how to make such a display-once notice. Keep it around in case you need it sometime in the future.

Upgrading the PHP, MySQL, and Perl software at that old server, before the move, would have resulted in the same sudden need to fix things. Legacy stuff. It wasn't the server move that broke things. It was the later versions of the software running on the server.

Implementing the Notice

Here is source code to show how the display-once notice is implemented at the Willmaster.com website. Notes follow.

<div id="message-holder" style="display:none; font-size:1rem; position:absolute; left:0; right:0; top:1in;">

<div id="message-div" style="position:relative; max-width:550px; margin:0 auto;border:3px solid #ccc; background-color:white; padding:2em 1em; border-radius:1em;">

<div style="position:absolute; top:2px; right:2px;">
<a href="javascript:CloseMessageGood();">(DISMISS)</a>
</div>

<div style="display:table; margin:0 auto;">
{{MESSAGE}}
</div>

<div style="position:absolute; bottom:2px; left:2px;">
<a href="javascript:CloseMessageGood();">(DISMISS)</a>
</div>

</div><!-- id="message-div" -->

</div><!-- id="message-holder" -->

<script>
if( ! document.cookie.match(/temporaryMessageCookie\=closed/) )
{
   document.getElementById("message-holder").style.display="block";
}
function CloseMessageGood()
{
   document.getElementById("message-holder").style.display="none";
   document.cookie = "temporaryMessageCookie=closed; path=/; secure";
}
</script>

Notes:

To accommodate various screen widths, the notice message is in a div that is inside another div.

The outside div (id="message-holder") is coded for the entire screen width. It is absolutely positioned to correctly place everything it holds.

The message div (id="message-div") is coded for a maximum width that makes the message look good. It is centered within the outer div. The message div will shrink within browsers narrower than the maximum width. (You may change the max-width:550px; and other CSS to accomodate your preferred style.)

The {{MESSAGE}} placeholder is for your message to your site visitiors.

The message div has "Dismiss" links. Tapping one sets a cookie that prevents the message from appearing again.

Implementing a JavaScript Alert Box Notice

If you prefer to omit all that HTML message coding and deliver your message with a JavaScript alert box, this is how it can be done. Notes follow.

<script>
if( ! document.cookie.match(/temporaryMessageCookiePS\=showed/) )
{
   alert("{{MESSAGE}}");
}
document.cookie = "temporaryMessageCookiePS=showed; path=/; secure";
</script>

Notes for the JavaScript Alert Box Notice:

When you replace the {{MESSAGE}} placeholder with your own message, any double quotes (") must be escaped. Escaping a character consists of preceding the character with a backward slash (\). An escaped double quote looks like this: \"

When the alert box appears, a cookie is set so the alert doesn't happen again for that browser.

Because the browser decides where to place the alert box with the message, you don't need to specify it.

When the alert box has appeared once, a cookie is set to prevent it from appearing again.

Reason

Although the sudden emergency of broken functions appeared when the website was moved to another server, it wasn't the server's fault. The server contained newer versions of the software used to run the site.

Because it was realized that it would take some time to fix the many issues related to software versions, the display-once notice was developed and deployed.

The display-once notice will be published on the Willmaster website until it appears that I've fixed all breaks.

(This article first appeared in Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC