Foros del Web » Programando para Internet » Javascript »

¿Cómo abro un popup desde un javascript?

Estas en el tema de ¿Cómo abro un popup desde un javascript? en el foro de Javascript en Foros del Web. Hola amig@s!! Necesito resolver un problema que tengo con este menú: <script languaje="javascript> // Añadir esto justo encima de </head> --> IE=document.all; NS=document.layers; /* Configure ...
  #1 (permalink)  
Antiguo 15/12/2003, 18:10
 
Fecha de Ingreso: noviembre-2003
Ubicación: Zaragoza, España
Mensajes: 1.257
Antigüedad: 20 años, 5 meses
Puntos: 154
¿Cómo abro un popup desde un javascript?

Hola amig@s!!

Necesito resolver un problema que tengo con este menú:



<script languaje="javascript>
// Añadir esto justo encima de </head> -->
IE=document.all;
NS=document.layers;
/*
Configure menu styles below
NOTE: To edit the link colors, go to the STYLE tags and edit the ssm2Items colors
*/
hdrFontFamily="Arial Black";
hdrFontSize="3";
hdrFontColor="#FFFFCC";
hdrBGColor="#993366";
linkFontFamily="Arial Black";
linkFontSize="2";
linkFontColor="#FFFFCC";
linkBGColor="#ffffff";
linkOverBGColor="#C0C0C0";
linkTarget="_parent";
YOffset=40;
staticYOffset=20;
menuBGColor="#993366";
menuIsStatic="yes";
menuHeader=" Menu de Mi sitio We"
menuWidth=180; // Must be a multiple of 5!
staticMode="advanced"
barBGColor="#993366";
barFontFamily="Arial Black";
barFontSize="3";
barFontColor="#FFFFCC";
barText="Pasar el puntero";

function moveOut() {
if (window.cancel) {cancel="";}
if (window.moving2) {clearTimeout(moving2); moving2="";}
if ((IE && ssm2.style.pixelLeft<0)||(NS && document.ssm2.left<0)) {
if (IE) {ssm2.style.pixelLeft += (5%menuWidth);}
if (NS) {document.ssm2.left += (5%menuWidth);}
moving1 = setTimeout('moveOut()', 10)}
else {clearTimeout(moving1)}};
function moveBack() {
cancel = moveBack1()}
function moveBack1() {
if (window.moving1) {clearTimeout(moving1)}
if ((IE && ssm2.style.pixelLeft>(-menuWidth))||(NS && document.ssm2.left>(-140))) {
if (IE) {ssm2.style.pixelLeft -= (5%menuWidth);}
if (NS) {document.ssm2.left -= (5%menuWidth);}
moving2 = setTimeout('moveBack1()', 10)}
else {clearTimeout(moving2)}};

lastY = 0;
function makeStatic(mode) {
if (IE) {winY = document.body.scrollTop;var NM=ssm2.style}
if (NS) {winY = window.pageYOffset;var NM=document.ssm2}
if (mode=="smooth") {
if ((IE||NS) && winY!=lastY) {
smooth = .2 * (winY - lastY);
if(smooth > 0) smooth = Math.ceil(smooth);
else smooth = Math.floor(smooth);
if (IE) NM.pixelTop+=smooth;
if (NS) NM.top+=smooth;
lastY = lastY+smooth;}
setTimeout('makeStatic("smooth")', 1)}
else if (mode=="advanced") {
if ((IE||NS) && winY>YOffset-staticYOffset) {
if (IE) {NM.pixelTop=winY+staticYOffset}
if (NS) {NM.top=winY+staticYOffset}}
else {
if (IE) {NM.pixelTop=YOffset}
if (NS) {NM.top=YOffset-7}}
setTimeout('makeStatic("advanced")', 1)}}

function init() {
if (IE) {
ssm2.style.pixelLeft = -menuWidth;
ssm2.style.visibility = "visible"}
else if (NS) {
document.ssm2.left = -menuWidth;
document.ssm2.visibility = "show"}
else {alert('Choose either the "smooth" or "advanced" static modes!')}}

//-->

</script>


</head>



// Cambiar la etiqueta <body> por:-->
//<BODY bgcolor="#edeee0" leftmargin="0" topmargin="0" marginwidth="0" marginheight="5" onLoad="init()">
// Añadir esto justo debajo: -->
if (IE) {document.write('<DIV ID="ssm2" style="visibility:hidden;Position : Absolute ;Left : 0px ;Top : '+YOffset+'px ;Z-Index : 20;width:1px" onmouseover="moveOut()" onmouseout="moveBack()">')}
if (NS) {document.write('<LAYER visibility="hide" top="'+YOffset+'" name="ssm2" bgcolor="'+menuBGColor+'" left="0" onmouseover="moveOut()" onmouseout="moveBack()">')}
tempBar=""
for (i=0;i<barText.length;i++) {
tempBar+=barText.substring(i, i+1)+"<BR>"}
document.write('<table border="1" cellpadding="0" cellspacing="1" width="'+(menuWidth+16+2)+'" bgcolor="'+menuBGColor+'"><tr><td bgcolor="'+hdrBGColor+'" WIDTH="'+menuWidth+'"> <font face="'+hdrFontFamily+'" Size="'+hdrFontSize+'" COLOR="'+hdrFontColor+'"><b>'+menuHeader+'</b></font></td><td align="center" rowspan="100" width="16" bgcolor="'+barBGColor+'"><p align="center"><font face="'+barFontFamily+'" Size="'+barFontSize+'" COLOR="'+barFontColor+'"><B>'+tempBar+'</B></font></p></TD></tr>')
function addItem(text, link, target) {
if (!target) {target=linkTarget}
document.write('<TR><TD BGCOLOR="'+linkBGColor+'" onmouseover="bgColor=\''+linkOverBGColor+'\'" onmouseout="bgColor=\''+linkBGColor+'\'"><ILAYER>< LAYER onmouseover="bgColor=\''+linkOverBGColor+'\'" onmouseout="bgColor=\''+linkBGColor+'\'" WIDTH="100%"><FONT face="'+linkFontFamily+'" color="'+linkFontColor+'" Size="'+linkFontSize+'"> <A HREF="'+link+'" target="'+target+'" CLASS="ssm2Items">'+text+'</LAYER></ILAYER></TD></TR>')}
function addHdr(text) {
document.write('<tr><td bgcolor="'+hdrBGColor+'" WIDTH="120"> <font face="'+hdrFontFamily+'" Size="'+hdrFontSize+'" COLOR="'+hdrFontColor+'"><b>'+text+'</b></font></td></tr>')}

//Only edit the script between HERE

addItem('Título', 'http://www.dominio.com/index.html', '');
addItem('Título2', 'http://www.dominio.com/2.html', '');
addItem('Título3', 'http://www.dominio.com/3.html', '');
addItem('Título4', 'http://www.dominio.com/4.html', '');
addItem('Popup1', 'http://www.dominio.com/5.html', '');
addItem('Popup2', 'http://www.dominio.com/6.html', '');
// and HERE! No more!

document.write('<tr><td bgcolor="'+hdrBGColor+'"><font size="2" face="Arial Black"> </font></td></TR></table>')
if (IE) {document.write('</DIV>')}
if (NS) {document.write('</LAYER>')}
if ((IE||NS) && (menuIsStatic=="yes"&&staticMode)) {makeStatic(staticMode);}
</script>


Lo que necesito es saber cómo abrir un popup desde este menú, porque tal como está abre todo en la misma página, además el popup debe ser sin barra de estado, scroll, dirección ... Vamos sólo la ventana y para más colmo centrada .

Espero que alguien me pueda ayudar porque además me corre mucha prisa (lo quieren para YA ).

Muchas gracias por anticipado.

Rubén
  #2 (permalink)  
Antiguo 16/12/2003, 04:03
Avatar de KarlanKas
Moderador extraterrestre
 
Fecha de Ingreso: diciembre-2001
Ubicación: Madrid
Mensajes: 6.987
Antigüedad: 22 años, 4 meses
Puntos: 61
Prueba a Sustituir las lineas;

addItem('Título', 'http://www.dominio.com/index.html', '');
addItem('Título2', 'http://www.dominio.com/2.html', '');
addItem('Título3', 'http://www.dominio.com/3.html', '');
addItem('Título4', 'http://www.dominio.com/4.html', '');
addItem('Popup1', 'http://www.dominio.com/5.html', '');
addItem('Popup2', 'http://www.dominio.com/6.html', '');

Por estas:

addItem('Título', 'http://www.dominio.com/index.html', '_blank');
addItem('Título2', 'http://www.dominio.com/2.html', '_blank');
addItem('Título3', 'http://www.dominio.com/3.html', '_blank');
addItem('Título4', 'http://www.dominio.com/4.html', '_blank');
addItem('Popup1', 'http://www.dominio.com/5.html', '_blank');
addItem('Popup2', 'http://www.dominio.com/6.html', '_blank');
__________________
Cómo escribir

No hay pregunta tonta, sino tonto que quiere seguir en la ignorancia.
  #3 (permalink)  
Antiguo 16/12/2003, 04:58
Avatar de KarlanKas
Moderador extraterrestre
 
Fecha de Ingreso: diciembre-2001
Ubicación: Madrid
Mensajes: 6.987
Antigüedad: 22 años, 4 meses
Puntos: 61
O mejor cambia la funcion AddItem por esta:
Código PHP:
function addItem(textlinktarget) {
document.write('<TR><TD BGCOLOR="'+linkBGColor+'" onmouseover="bgColor=''+linkOverBGColor+''" onmouseout="bgColor=''+linkBGColor+''"><ILAYER>');
document.write('<LAYER onmouseover="bgColor=''+linkOverBGColor+''" onmouseout="bgColor=''+linkBGColor+''" WIDTH="100%"><FONT face="'+linkFontFamily+'" color="'+linkFontColor+'" Size="'+linkFontSize+'">');
document.write('<A HREF="#" onclick="pepe=window.open(\''+link+'\',\'ventana\',\'width='+ancho+',height='+alto+',top='+(screen.height-alto)/2+',left='+(screen.width-ancho)/2+'\');return false;" CLASS="ssm2Items">'+text+'</LAYER></ILAYER></TD></TR>')

__________________
Cómo escribir

No hay pregunta tonta, sino tonto que quiere seguir en la ignorancia.

Última edición por KarlanKas; 16/12/2003 a las 05:00
  #4 (permalink)  
Antiguo 16/12/2003, 13:53
 
Fecha de Ingreso: noviembre-2003
Ubicación: Zaragoza, España
Mensajes: 1.257
Antigüedad: 20 años, 5 meses
Puntos: 154
De acuerdo Muchas gracias

Muchas gracias Karlankas

Me quedo con la primera opción porque sólo tengo que abrir
como popup 2 de los enlaces y de la otra manera se abrirían
todos en otra ventana.

El otro problema es que al cerrar por medio de:


<html>
<head>
<script language="JavaScript">

function cerrar() {
var ventana = window.self;
ventana.opener = window.self;
ventana.close();
}

</script>
</head>
<body>
Problema:<br>
<a href="#" onClick="window.close()">
Cerrar ventana de modo tradicional (el navegador pedirá confirmación)
</a><br><br>
Solución:<br>
<a href="#" onClick="cerrar()">
Cerrar ventana sin confirmación
</a>
</body>
</html>


también se abre otra ventana y al no tener la función da un error.

¿Cómo lo podría solucionar?

Me queda otra duda:

¿Como hago para abrirlo con condiciones (si barras, sin resize, etc.)?

Cuando se abre desde html es con este código, que está en las faqs:


<html>
<head>
<script language="JavaScript">
function abrirVentana() {
open("popUp.htm","miVentana", "toolbar=no,directories=no,menubar=no,status=n o");
}
</script>
</head>
<body>
<form name="frm">
<input type="button" name="boton" value="PopUp" onClick="abrirVentana()">
</form>
</body>
</html>


Pero esto es al abrirlo desde HTML, ¿se puede hacer incluyendo la funcion en
el propio menú de javascript o hay que hacerlo de otra manera?


Espero que puedas ayudarme, muchas gracias por adelantado.

Un saludo

Rubén
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:25.