javascript如何实现弹出窗口
不可能不拦截,凡是由程序自动执行打开的新窗口都会被拦截,只有当你的新窗口是由用户主动激活某个程序打开的才不会,
凡是有JavaScript自动打开的窗口都可以使用关闭功能,否则浏览器要么阻止要么直接忽略,打开用window,open();关闭用window.cloas();定位新窗口需要用到浏览器bom,在open中添加相应参数即可,参数很繁琐建议上网查
js相关,下面这段代码书上说有弹窗,为什么我执行了没有
你说的这个弹窗,是指的弹出一个alert吗?反正我看了看,只有这个alert。
另外,对于为什么没有弹出alert,是因为你写的document.getElementById(“save“),不对,应该是document.getElementByTagName(“save“), 因为你的input给的name是save,而不是id。
除非你的input是这样写的:《input id=“save“ type=“button“ value=“保存“》, 这个时候,才可以用document.getElementById(“save“), 这样才能取到input对象。
书中也写错了。
手机网站首页弹窗JS代码
// 注意引用jquery.js 和 jquery.cookie.js
$(function () {
var date = new Date().getDay();
if($.cookie(“date“) == undefined || $.cookie(“date“) == null){
// 说明当天没有打开这个弹窗,打开弹窗
alert(“弹窗内容自己写,可以使用dialog“);
$.cookie(“date“,date,7); //cookie 的有效时间 为 7 天
}else{
var cookieTime = $.cookie(“date“); // 获取cookie保存的时间
if(cookieTime != date){
alert(“弹窗内容自己写,可以使用dialog“);
$(“.alert-info“).dialog(“open“);
}
}
});
求js弹窗代码
给个思路,js是不可以直接获取客户端ip的,也是IP用户。需要服务器后端提供API给到前端。
我们可以利用AJAX去请求。拿到用户的IP后,弹窗一次。用cookie缓存1个小时。用户在每次重载页面或者进入其他页面的话,JS里,每次都去判断,缓存是否过期,若过期了,重新获取IP,再弹窗,再用cookie缓存1个小时。
JavaScript怎么实现网页右下角弹出窗口代码
《html》
《head》
《metahttp-equiv=“Content-Type“ content=“text/html;charset=utf-8“ /》
《title》JavaScript实现网页右下角弹出窗口代码《/title》
《/head》
《style type=“text/css“》
#winpop { width:200px; height:0px;position:absolute; right:0; bottom:0; border:1px solid #666; margin:0;padding:1px; overflow:hidden; display:none;}
#winpop .title { width:100%; height:22px;line-height:20px; background:#FFCC00; font-weight:bold; text-align:center;font-size:12px;}
#winpop .con { width:100%; height:90px;line-height:80px; font-weight:bold; font-size:12px; color:#FF0000;text-decoration:underline; text-align:center} /* http://www.webdm.cn */
#silu { font-size:12px; color:#666;position:absolute; right:0; text-align:right; text-decoration:underline;line-height:22px;}
.close { position:absolute; right:4px;top:-1px; color:#FFF; cursor:pointer}
《/style》
《scripttype=“text/javascript“》
function tips_pop(){
var MsgPop=document.getElementById(“winpop“);
var popH=parseInt(MsgPop.style.height);//将对象的高度转化为数字
if (popH==0){
MsgPop.style.display=“block“;//显示隐藏的窗口
show=setInterval(“changeH(’up’)“,2);
}
else {
hide=setInterval(“changeH(’down’)“,2);
}
}
function changeH(str) {
varMsgPop=document.getElementById(“winpop“);
varpopH=parseInt(MsgPop.style.height);
if(str==“up“){
if(popH《=100){
MsgPop.style.height=(popH+4).toString()+“px“;
}
else{
clearInterval(show);
}
}
if(str==“down“){
if(popH》=4){
MsgPop.style.height=(popH-4).toString()+“px“;
}
else{
clearInterval(hide);
MsgPop.style.display=“none“; //隐藏DIV
}
}
}
window.onload=function(){//加载
document.getElementById(’winpop’).style.height=’0px’;
setTimeout(“tips_pop()“,800);//3秒后调用tips_pop()这个函数
}
《/script》
《body》
《div id=“silu“》
《buttononclick=“tips_pop()“》3秒后会在右下角自动弹出窗口,如果没有弹出请点击这个按钮《/button》
《/div》
《div id=“winpop“》
《div》您有新的短消息!《spanclass=“close“onclick=“tips_pop()“》X《/span》《/div》
《div》1条《ahref=“http://www.luenuo.com“》经典语录《/a》(《/div》
《/div》
《/body》
《/html》
js强制弹窗代码,防止浏览器拦截
之所以iframe以外的会弹出,是因为JS的作用仅限于本窗口,iframe以外的,不是本窗口,所以也管不了了,具体要怎么做,得看你的代码
大概思路就是,在父窗口里写个函数去管这事如function1(),在iframe里,用window.parent.function1()去调用,建议参考一下window.parent的用法
怎么用js弹出提示框
弹出提示框一般有3种
1)alert (普通提示框)
2)prompt (可输入的提示框)
3)confirm (可选择的提示框)
下面举个例子:
《!doctype html》
《html lang=“en“》
《head》
《meta charset=“UTF-8“》
《title》Document《/title》
《/head》
《body》
《button onclick=“mal()“》第一种:alert《/button》
《button onclick=“mpro()“》第二种:prompt《/button》
《button onclick=“mcon()“》第三种:confirm《/button》
《script》
function mal(){
alert(’这是一个普通的提示框’);
}
function mpro(){
var val = prompt(’这是一个可输入的提示框’,’这个参数为输入框默认值,可以不填哦’);
//prompt会把输入框的值返回给你
}
function mcon(){
var boo = confirm(’这是一个可选择的提示框,3种提示方式,学会了吗?’)
//confirm 会返回你选择的选项,然后可以依据选择执行逻辑
if(boo){
alert(’学会了,真聪明’);
}else{
alert(’再来一遍吧’)
}
}
《/script》
《/body》
《/html》
求一段js代码打开页面div5秒弹出,点击关闭按钮后再次定时弹出
《!DOCTYPE html》
《html》
《head》
《meta charset=“utf-8“/》
《title》定时弹窗《/title》
《style type=“text/css“》
html,body{
width:100%;
height:100%;
margin:0;
padding:0;
}
.box{
width:100%;
}
.tc-box{
width:25%;
margin:80px auto;
border:1px solid #f00;
text-align: center;
line-height: 150px;
}
《/style》
《/head》
《body》
《div class=“box“》
《div class=“tc-box“ id=“tc“》
《div class=“tc-cont“》我是弹窗内容《/div》
《button id=“btn“》点击关闭《/button》
《/div》
《/div》
《script type=“text/javascript“》
var btn = document.getElementById(’btn’);
btn.onclick = function(){
var tc = document.getElementById(’tc’);
tc.style.display = ’none’;
}
function xs(){
var tc = document.getElementById(’tc’);
tc.style.display = ’block’;
console.log(’aaaaaaa’);
}
var lia = window.setInterval(xs,5000);
《/script》
《/body》
《/html》
点击关闭之后5秒就会自动弹出
上面的代码有点不太合理,下面代码优化了一下。
《!DOCTYPE html》
《html》
《head》
《meta charset=“utf-8“/》
《title》定时弹窗《/title》
《style type=“text/css“》
html,body{
width:100%;
height:100%;
margin:0;
padding:0;
}
.box{
width:100%;
}
.tc-box{
width:35%;
margin:80px auto;
border:1px solid #f00;
text-align: center;
line-height: 150px;
}
《/style》
《/head》
《body》
《div class=“box“》
《div class=“tc-box“ id=“tc“》
《div class=“tc-cont“》我是弹窗内容《/div》
《button id=“btn“》点击关闭5秒后继续弹出《/button》
《button id=“btn1“》点击关闭,不再弹窗《/button》
《/div》
《/div》
《script type=“text/javascript“》
var btn = document.getElementById(’btn’);
function xs(){
var tc = document.getElementById(’tc’);
tc.style.display = ’block’;
tc.classList.remove(’on’);
console.log(’aaaaaaa’);
}
btn.onclick = function(){
var tc = document.getElementById(’tc’);
tc.style.display = ’none’;
var lia = window.setInterval(’xs()’,5000);
tc.classList.add(’on’); //添加一个on类
if(tc.classList.contains(’on’) == true){ //查询类
function dsq(){
window.clearInterval(lia);
}
window.setTimeout(dsq,5000);
}
}
// 清除定时器
var btn1 = document.getElementById(’btn1’);
btn1.onclick = function(){
var tc = document.getElementById(’tc’);
tc.style.display = ’none’;
}
《/script》
《/body》
《/html》
因为一直弹窗会对浏览器产生很大的负荷,这里除了添加不再弹窗之外还优化了一下代码。
之前的代码是点击之后开始执行循环函数,但是不停止循环,不管弹窗是否显示的状态都会每5秒执行一次,这样明显不合理,应该是在你关闭弹窗之后5秒才执行。弹窗在显示状态不执行。
JavaScript只有一段关于弹窗显示的代码,想要在网页中,显示两个弹窗可以如何实现
这个要看具体的代码实现。
如果代码实现是显示/隐藏原本在HTML中的元素,那就把隐藏的元素复制一份,JS代码复制一份改改名字就可以,虽然低端,胜在实现快。
如果是动态创建,那就复杂一点了,需要修改创建的元素的标识来分别对应不同的弹窗。包括创建的元素ID,创建出的元素的关闭按钮绑定事件等等。
如果考虑第三方组件,那就很多了,layerui里的layer组件是个不错的选择。