gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:38:21 27 4
gpt4 key购买 nike

正在处理一个类项目,我想要一个 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>

最佳答案

您必须在警报中转义引号。
您当前的字符串是

'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.'

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

关于页面加载时的 Javascript 警报和页面退出时的警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43576651/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com