Javascript 页面退出警报消息在Firefox中不工作
嗨,我在一个页面上有我的javscript警报,该页面用我的自定义消息提醒用户 关于我的脚本,当用户尝试退出或刷新页面时,他们会收到我的自定义消息警报 “请继续浏览此页面以获得折扣” 当他们选择留下来时,他们会被重定向到 折扣优惠.html 我的脚本:Javascript 页面退出警报消息在Firefox中不工作,javascript,html,javascript-events,Javascript,Html,Javascript Events,嗨,我在一个页面上有我的javscript警报,该页面用我的自定义消息提醒用户 关于我的脚本,当用户尝试退出或刷新页面时,他们会收到我的自定义消息警报 “请继续浏览此页面以获得折扣” 当他们选择留下来时,他们会被重定向到 折扣优惠.html 我的脚本: <script language="javascript"> var vals=0; function displayMsg() { window.onbeforeunload = function e
<script language="javascript">
var vals=0;
function displayMsg() {
window.onbeforeunload = function evens(evt) {}
window.location.href = 'discount_offer.html';
}
window.onbeforeunload = function evens(evt) {
var message = 'Please Stay on this page to avail discount';
if (typeof evt == 'undefined') {
evt = window.event;
}
timedCount();
vals++;
if (evt) {
evt.returnValue = message ;
return message ;
}
trace(evt);
}
function timedCount()
{
t=setTimeout("timedCount()",100);
if(vals>0)
{
displayMsg();
clearTimeout(t);
}
}
</script>
<p> <h1> My page Content here! </h1> </p>
var-vals=0;
函数displayMsg(){
window.onbeforeunload=函数evens(evt){}
window.location.href='discount_offer.html';
}
window.onbeforeunload=函数evens(evt){
var消息='请留在本页以获得折扣';
如果(evt的类型==‘未定义’){
evt=window.event;
}
timedCount();
VAL++;
如果(evt){
evt.returnValue=消息;
返回消息;
}
跟踪(evt);
}
函数timedCount()
{
t=设置超时(“timedCount()”,100);
如果(VAL>0)
{
displayMsg();
清除超时(t);
}
}
我的页面内容在这里
>问题:
<script language="javascript">
var vals=0;
function displayMsg() {
window.onbeforeunload = function evens(evt) {}
window.location.href = 'discount_offer.html';
}
window.onbeforeunload = function evens(evt) {
var message = 'Please Stay on this page to avail discount';
if (typeof evt == 'undefined') {
evt = window.event;
}
timedCount();
vals++;
if (evt) {
evt.returnValue = message ;
return message ;
}
trace(evt);
}
function timedCount()
{
t=setTimeout("timedCount()",100);
if(vals>0)
{
displayMsg();
clearTimeout(t);
}
}
</script>
<p> <h1> My page Content here! </h1> </p>
我的脚本在Chrome中工作得很好,但在Firefox中它没有显示我的自定义消息。相反,它显示一条Firefox默认消息:**
“此页面要求您确认是否要离开-您输入的数据可能无法保存”
>我的问题是:
<script language="javascript">
var vals=0;
function displayMsg() {
window.onbeforeunload = function evens(evt) {}
window.location.href = 'discount_offer.html';
}
window.onbeforeunload = function evens(evt) {
var message = 'Please Stay on this page to avail discount';
if (typeof evt == 'undefined') {
evt = window.event;
}
timedCount();
vals++;
if (evt) {
evt.returnValue = message ;
return message ;
}
trace(evt);
}
function timedCount()
{
t=setTimeout("timedCount()",100);
if(vals>0)
{
displayMsg();
clearTimeout(t);
}
}
</script>
<p> <h1> My page Content here! </h1> </p>
如何删除此默认firefox消息并显示我的消息?不,您无法更改它: 在FF 4和更高版本中,返回的字符串不会显示给用户,如下所示
另一种解决方案是突出显示未保存的字段和/或在页面上的某个位置放置消息。非常好的信息!从来没有想过这个问题是在Firefox版本中,而不是在我的脚本中。非常有用的信息为一些人与类似的要求,并努力获得这。。谢谢你,基罗!