Callat
Callat

Reputation: 3044

Javascript alert on page load and alert on page exit

Working on a project for class and I want a javascript event that gives a pop-up on a page load and a pop up when the user navigates away. I try to handle it with onload and onunload events embedded directly in my html but it doesn't appear to be working on chrome and on internet explorer I seem to only get the unload message. The code is as follows:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>teest</title>
    <!-- [if lt IE 9]>
    <script src = "http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif] -->
    <link rel="stylesheet" href="css/contact.css" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0"> <!-- viewport tag configuration -->
    <link rel="shortcut icon" href="img/favicon.ico" />
  </head>
  <body onload = "alert('Even if you aren't interested, please give our design some feedback as we would like to stay current.')" onunload = "alert('Thank you for your time and consideration!')">
        <header class = "head">
          <h1>
          <img src="img/coa.png" display="inline-block"  height="150px" float="left"/>
          other stuff</h1>
          <p>stuffsy</p>
        </header>

Upvotes: 1

Views: 743

Answers (1)

Christian Valentin
Christian Valentin

Reputation: 519

You have to escape your quotes in the alert.
Your current string is

'Even if you aren't interested, please give our design some feedback as we would like to stay current.'

And your have to change it to

'Even if you aren\'t interested, please give our design some feedback as we would like to stay current.'

So it will recognize your string the right way

Upvotes: 3

Related Questions