Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6238071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:08:46+00:00 2026-05-24T11:08:46+00:00

I’d like to set up an alert message that appears at the top of

  • 0

I’d like to set up an alert message that appears at the top of my application on the first time a user accesses it, and persists until the user dismisses it.

I’m kinda new to jQuery, but I’d like to use it for this. Does jQuery have some built in methods for this kind of thing? Ideally I’d like it to be an instant action, rather than a form variable.

My app is a PHP based WordPress plugin.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:08:46+00:00Added an answer on May 24, 2026 at 11:08 am

    You can create a twitter-like alert by following the steps on these tutorials.

    CSS:

    #alert
    {
        overflow: hidden;
        z-index: 999;
        width: 100%;
        text-align: center;
        position: absolute;
        top: 0;
        left: 0;
        background-color: #fff;
        height: 0;
        color: #000;
        font: 20px/40px arial, sans-serif;
        opacity: .9;
    }
    

    jQuery

    Check if
    Use setTimeout to collapse the alert after 3 seconds
    Expand the alert to CSS line-height or 50px if line-height is not set
    If the user clicks alert before 3 seconds, collapse the alert early

    $(function () {
        var $alert = $('#alert');
        if($alert.length)
        {
            var alerttimer = window.setTimeout(function () {
                $alert.trigger('click');
            }, 3000);
            $alert.animate({height: $alert.css('line-height') || '50px'}, 200)
            .click(function () {
                window.clearTimeout(alerttimer);
                $alert.animate({height: '0'}, 200);
            });
        }
    });
    

    Put CSS and jQuery in an HTML page

    Some things to note:

    Line 1: Turn on session with PHP
    Line 13: There’s our alert CSS
    Line 30: If $_SESSION[‘alert’] exists (set in submit.php in step 2)
    Line 40: Use jQuery hosted by Google
    Line 42: There’s our alert jQuery

    <?php session_start(); ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <title>Twitter-like alert message</title>
            <style type="text/css">
            body
            {
                background-color: #ccc;
                color: #000;
                padding: 30px;
            }
            #alert
            {
                overflow: hidden;
                width: 100%;
                text-align: center;
                position: absolute;
                top: 0;
                left: 0;
                background-color: #fff;
                height: 0;
                color: #000;
                font: 20px/40px arial, sans-serif;
                opacity: .9;
            }
            </style>
        </head>
        <body>
            <?php
            if(!empty($_SESSION['display']))
            {
                echo '<div id="alert">' . $_SESSION['display'] . '</div>';
                unset($_SESSION['display']);
            }
            ?>
            <form method="post" action="submit.php">
                <label for="message">Message</label> <input type="text" name="message"> <input type="submit" value="Alert me!">
            </form>
            <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
            <script type="text/javascript">
            $(function () {
                var $alert = $('#alert');
                if($alert.length)
                {
                    var alerttimer = window.setTimeout(function () {
                        $alert.trigger('click');
                    }, 3000);
                    $alert.animate({height: $alert.css('line-height') || '50px'}, 200)
                    .click(function () {
                        window.clearTimeout(alerttimer);
                        $alert.animate({height: '0'}, 200);
                    });
                }
            });
            </script>
        </body>
    </html>
    

    Use PHP to add the alert to the $_SESSION

    Save this file as submit.php

    <?php
    session_start();
    
    $themessage = get_magic_quotes_gpc() ?
        stripslashes(trim($_POST['message'])) :
        trim($_POST['message']);
    
    $_SESSION['display'] = $themessage;
    
    header('Location: ' . $_SERVER['HTTP_REFERER']);
    exit;
    ?>
    

    It will create something similar to this
    http://www.youtube.com/watch?v=BbJeYdPRKXw&feature=player_embedded

    Comment below if you have any questions on the code, I guess this is all you need.

    Credits to:
    http://briancray.com/2009/05/06/twitter-style-alert-jquery-cs-php/
    http://www.achari.in/create-twitter-alert-style-using-jquery-js-and-css

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.