Creating Alerts

Creating AlertsSo you've seen those annoying websites that have alert boxes appearing every time you click or open something and wondered how to do it? Well here's your answer.

Firstly, your basic command for an alert box in javascript is

alert('This is an alert box!')

The above code will produce an alert box with the text "This is an alert box!" inside it.

So, how do you use it?

Well first of all, let's try making an alert appear when you open a web page. In the <head> of your (X)HTML page, add the following:

<script language="JavaScript">
alert('Welcome to my site!');
</script>

Now, when you open your webpage, the alert box will come up and the user must press the OK button before the rest of the site loads.

However, you are not just limited to one alert box! You can have as many as you like! How? Just add more alerts! For example:

<script language="JavaScript">
alert('Hello!');
alert('Welcome to my brand new website!');
alert('Remember to check out the forums!');
alert('And please sign the guestbook!');
alert('I hope you enjoy your visit!');
</script>

The user will have to click OK to all of these alerts before the page loads.

Another use for the alert box is when the user hovers their mouse over something on your page. This is how to do it:

<a onMouseOver="alert('The forums are still under construction!')">Forums</a>

The user will not be able to click this link as everytime they move their mouse over it, the alert box will appear and they cannot do anything else on your page until they have clicked the OK button to close the alert box.


Related Articles

  • Using Google Alerts to your Advantage
    Learn about search engine marketing benefits of using Google Alerts to analyze your rivals strategy and to keep track of your own link popularity.
  • JavaScript Alerts
    Well, you want to add one of those JavaScript alert boxes that come out of nowhere, dont you? Okay, lets begin with the alert box that just tells the viewer something you want them to know. Heres the alert command:
  • Google News - Just another Article Announcer?
    In Googles recent battle towards becoming an international news center, Ive come to notice that the results delivered from Google News seems like nothing more than the articles we publish everyday. So I ask, doesnt it seem like Google News resembles an article directory of some sorts?
  • JavaScript Password Protection
    OK, I finally got around to writing the javascript password protection tutorial. You will see the example script here is pretty straightforward, but it is also pretty easy to get around. Ill tell you why and give you links to more secure scripts later in this tutorial.
  • Sales Without Search Engines
    Imagine one day you flip on your PC, log on to the Internet and go to google.com. The browser alerts you and says that there is no website found at that address. No problem you think, as you head on over to Yahoo.com. Same thing. No website found at that url. Now something seems fishy...
  • SEO Trade Secrets - 8 Great Tools for Search Engine Optimization
    About 80% of website traffic comes through search engines. And research shows, if you
  • Pitching Bloggers: 15 Rules to Obey
    This very interesting article explains the strategy and etiguette behind blogging for publicity. The author covers 15 very good points with supporting logic and reason.
  • JavaScript Confirmation Boxes
    A javascript confirmation box can be a handy way to give your visitors a choice of whether or not an action is performed. A confirmation box will pop up much like an alert box, but will allow the viewer to press an OK or Cancel button.
  • My Google Wish List
    There are a number of wishes that I have for Googles future. While I would like number one ranking for all of my important keywords and phrases, but I would be willing to settle for Google acknowledging at least a few of my wishes that will benefit the search community as a whole.
  • Using The Online Press Release Link Building Strategy
    If you market any type of product or service, your online marketing strategy should include the distribution of online press releases. In this article you will learn how to get maximum profit from this excellent link building strategy.

Contact Web Design Outsource and get started today

Need Website Designing, Development, Redesigning, Maintenance and SEO services or help growing your company's web presence? Request a free Quote Now.