← Javascript

Abrir pop-up automaticamente

Lida 16058 vezes

Offline

Carlos Faria 
Membro
Mensagens 551 Gostos 5
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

Boa tarde,


Como faço para que essa pop-up abra automaticamente quando o utilizador entrar no site?


Código: [Seleccione]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>TESTE</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {

$('a[name=modal]').click(function(e) {
e.preventDefault();

var id = $(this).attr('href');

var maskHeight = $(document).height();
var maskWidth = $(window).width();

$('#mask').css({'width':maskWidth,'height':maskHeight});

$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);

//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
             
$(id).css('top',  winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);

$(id).fadeIn(2000);

});

$('.window .close').click(function (e) {
e.preventDefault();

$('#mask').hide();
$('.window').hide();
});

$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});

});

</script>

<style type="text/css">

#mask {
  position:absolute;
  left:0;
  top:0;
  z-index:9000;
  background-color:#000;
  display:none;
}
 
#boxes .window {
  position:absolute;
  left:0;
  top:0;
  width:440px;
  height:200px;
  display:none;
  z-index:9999;
  padding:20px;
}

#boxes #dialog2 {
  background:url(notice.png) no-repeat 0 0 transparent;
  width:326px;
  height:229px;
  padding:50px 0 20px 25px;
}

.close{display:block; text-align:right;}

</style>
</head>
<body>

<a href="#dialog2" name="modal">TESTE</a>


<div id="boxes">


<!-- Janela Modal com Bloco de Nota -->
<div id="dialog2" class="window">
Então?<br />
Construir uma <b>Janela Modal Simples</b> com o formato que você quiser é fácil!<br />
Simples e totalmente personalizável : ) <br /><br />
<input type="button" value="Fechar" class="close"/>
</div>
<!-- Fim Janela Modal com Bloco de Nota -->



<!-- Máscara para cobrir a tela -->
  <div id="mask"></div>

</div>

</body>
</html>


Desde já muito obrigado.
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

Tenho precisamente a mesma dúvida. Entretanto tinha arranjado outra solução, mas se alguém souber a solução :)
Pode ser esta "modal box" ou qualquer outra, pelo menos para mim...
Offline

Carlos Faria 
Membro
Mensagens 551 Gostos 5
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

Alguém?
Offline

Shaddz 
Membro
Mensagens 2324 Gostos 2
Feedback +9

Troféus totais: 29
Trófeus: (Ver todos)
Windows User Linux User Mobile User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4

<SCRIPT LANGUAGE="JavaScript">
<!--
window.alert('Olá! "')
// -->
</SCRIPT>

com isto abre logo
Offline

Carlos Faria 
Membro
Mensagens 551 Gostos 5
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

<SCRIPT LANGUAGE="JavaScript">
<!--
window.alert('Olá! "')
// -->
</SCRIPT>

com isto abre logo

O alert abre uma janela do windows, não é isso que quero. Se colocares aquele código num ficheiro html, vais ver que ao carregares em "TESTE" abre uma janela em JS e é essa janela que quero que seja carregada logo que o utilizador entrar na página.
Offline

Pedro Lopes 
Beta tester
Mensagens 3568 Gostos 18
Feedback +6

Troféus totais: 32
Trófeus: (Ver todos)
Level 6 Windows User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3

Usa antes o seguinte. ;)

Código: [Seleccione]
<script type="text/javascript">
$(document).ready(function() {

var maskHeight = $(document).height();
var maskWidth = $(window).width();

$('#mask').css({'width':maskWidth,'height':maskHeight});

$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);

//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
             
$('#dialog2').css('top',  winH/2-$('#dialog2').height()/2);
$('#dialog2').css('left', winW/2-$('#dialog2').width()/2);

$('#dialog2').fadeIn(2000);

$('.window .close').click(function (e) {
e.preventDefault();

$('#mask').hide();
$('.window').hide();
});

$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});

});
</script>
Offline

Carlos Faria 
Membro
Mensagens 551 Gostos 5
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

@ORiOn Muito Obrigado! :)