页面加载上的Javascript警报和页面退出时的警报

时间:2017-04-23 21:24:17

标签: javascript html

在课堂上处理项目,我想要一个javascript事件,它会在页面加载时弹出一个弹出窗口,并在用户导航时弹出。我尝试使用直接嵌入在我的html中的onloadonunload事件处理它,但它似乎没有在chrome和Internet Explorer上工作我似乎只得到卸载消息。代码如下:

<!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>

1 个答案:

答案 0 :(得分:3)

你必须在警报中逃避你的报价 您当前的字符串是

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

你必须把它改成

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

所以它会以正确的方式识别你的字符串