如何使用关闭按钮第一次加载页面时,如何在右侧添加弹出窗口 [英] How can I add popup window on right side when page loading 1st time with close button

查看:88
本文介绍了如何使用关闭按钮第一次加载页面时,如何在右侧添加弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们访问网站时,应该在右侧打开一个弹出窗口。



我尝试过:



我曾经尝试过,但它在每个刷新页面打开。

When we visit the website there should be open a popup window on right side.

What I have tried:

I had tried but it open at every refresh page.

推荐答案

你需要记住用户是否已经访问过该网站,只有在没有的情况下才显示该消息。



如果您的服务器端代码需要知道用户是否是第一次访问,那么我需要使用 cookie [ ^ ]。



如果你只需要从Javascript知道,那么使用本地存储:

Window.localStorage - Web APIs | MDN [ ^ ]

本地存储和如何使用它在网站上 - 粉碎杂志 [ ^ ]





然而,如果你是尝试打开新的浏览器窗口( window.open [ ^ ])那样不行。您的弹出窗口将被内置于每个主要浏览器的弹出窗口阻止程序阻止。相反,您需要在页面中显示您的消息,使用 jQuery UI的对话框 [ ^ ]或 Bootstrap的模态 [ ^ ]。
You'll need to remember whether the user has already visited the site, and only show the message if they haven't.

If your server-side code needs to know whether it's the user's first visit, you'll need to use a cookie[^].

If you only need to know from Javascript, then use local storage:
Window.localStorage - Web APIs | MDN[^]
Local Storage And How To Use It On Websites – Smashing Magazine[^]


However, if you're trying to open a new browser window (window.open[^]) automatically when the page loads, that will not work. Your popup will be blocked by the popup blocker built in to every major browser. Instead, you'll need to show your message within the page, using something like jQuery UI's Dialog[^] or Bootstrap's Modal[^].


这篇关于如何使用关闭按钮第一次加载页面时,如何在右侧添加弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆