简体   繁体   English

网页弹出

[英]Popup on webpage

I have a set of html webpages for my website. 我的网站有一套html网页。 The website has been fully completed except for the popup, which is supposed to be loaded automatically when a user accesses the homepage of the website. 该网站已完全完成,除了弹出窗口外,该弹出窗口应该在用户访问网站主页时自动加载。 This popup, which will be loaded in the middle of the homepage, will contain an image (900x400) with a close button on the top left of the popup. 该弹出窗口将加载到首页的中间,其中将包含一个图片(900x400),并在弹出窗口的左上方显示一个关闭按钮。

I have tried numerous sources and many of these web resources require the user to click on the link for the popup to appear. 我尝试了许多资源,其中许多Web资源都要求用户单击链接以显示弹出窗口。 I am not looking for the user to click to have the popup displayed. 我不是要用户单击以显示弹出窗口。 I want the user to be automatically shown the popup when the user accesses the homepage. 我希望用户访问主页时自​​动向其显示弹出窗口。

May someone please assist me through this issue? 有人可以帮我解决这个问题吗?

You could add a div with the CSS position:absolute , and create a close button for it: 您可以添加一个带有CSS position:absolutediv ,并为其创建一个close按钮:

 document.addEventListener('DOMContentLoaded', function() { document.querySelector('a.close').addEventListener('click', function(e) { document.getElementById('language-popup').style.display = 'none'; }); }); 
 #language-popup { background-color: #AAAAFF; font-family: Verdana; padding: 12px; border-radius: 10px; width: 900px; height: 400px; position: absolute; top: 50px; } #language-popup h3 { text-align: center; } #language-popup ul { list-style-type: none; } #language-popup a { text-decoration: none; color: black; } #language-popup a:hover { text-decoration: underline; } #language-popup .close { float: right; } #language-popup .close:hover { text-decoration: none; } #language-popup .close:after { content: '✖'; cursor: pointer; } 
 <div id="language-popup"> <a class='close'></a> <h3>Popup title</h3> <section> Your popup content goes here! </section> </div> 

You can use jQuery UI Dialog. 您可以使用jQuery UI对话框。 It can be shown anytime, onclick as well as onload of document. 它可以随时显示,onclick以及文档加载。 To implement it in your webpage, do this : 要在您的网页中实现它,请执行以下操作:

HTML: HTML:

<div id = "dialog">
<p>Some Content Here...</p>
</div>

jQuery: jQuery的:

$(document).ready(function(){
 $('#dialog').dialog();
});

Working demo from jQueryUI. jQueryUI的工作演示

Make sure that you insert jQuery, jQueryUI and jQueryUI.CSS in your markup by placing these tags in your markup: 通过将以下标记放置在标记中,确保在标记中插入jQuery,jQueryUI和jQueryUI.CSS:

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM