pilla
11-17-2002, 08:59 PM
Hi!
How can I get that a popup window loads different contents based on external js files?
I have tried changing the value of SRC when opening the popup window, but to no avail.
Any hint?
beetle
11-17-2002, 09:29 PM
Show us some of the code you're working with, then I can provide an answer....
pilla
11-17-2002, 10:14 PM
Here is the external js file I use in the page:
/*---------- BASE DATOS NOVEDADES ---------*/
function dbNovs(ncodigo, nestado, nsoporte, nautor, ntitulo, nampl, nano, npaginas, nanex1, nanex2, nanex3, neuros, nisbn, noferta, nindice) {
this.ncodigo = ncodigo;this.nestado = nestado;this.nsoporte = nsoporte;this.nautor = nautor;this.ntitulo = ntitulo;this.nampl = nampl;this.nano = nano; this.npaginas = npaginas;this.nanex1 = nanex1;this.nanex2 = nanex2;this.nanex3 = nanex3;this.neuros = neuros;this.nisbn = nisbn;this.noferta = noferta;this.nindice = nindice;this.toString = format_dbNovs;
}
/*---------- FORMATO DATOS NOVEDADES ---------*/
function format_dbNovs() {
indi = "Indice";
cod = this.ncodigo;
text= "<tr><td ALIGN=LEFT VALIGN=TOP CLASS='lautor'>" + this.nautor + "<\/td><td><\/td><td ALIGN=CENTER VALIGN=CENTER ROWSPAN='3' CLASS='loferta'>" + this.noferta + "<\/td><\/tr>";
text += "<tr><td ALIGN=LEFT VALIGN=TOP CLASS='ltitulo'>" + this.ntitulo + this.nampl + "<br> " + "<\/td><td CLASS='lsoporte'>" + this.nsoporte + "<\/td><td><\/td><\/tr>";
text += "<tr><td ALIGN=LEFT VALIGN=TOP CLASS='lano'>" + this.nano + " - " + this.npaginas + " pp. - " + this.nanex1.toLowerCase() + " - " + this.nanex2.toLowerCase() + " - " + this.nanex3.toLowerCase() + " ";
text += "<a href=\"javascript:IndiceWindow(this.ncodigo)\""
text += ">" + this.nindice;
text += "<\/a><\/td>";
text += "<td ALIGN=LEFT CLASS='lano'>€ " + this.neuros + "<br> <\/td><td><\/td><\/tr>";
text += "<tr><td bgcolor='#FFFAF0'> <\/td><td bgcolor='#FFFAF0'> <\/td><td bgcolor='#FFFFFF'> <\/td><\/tr>";
return text;
}
/*---------- PINTA DATOS NOVEDADES ---------*/
function printNove() {
for (var i=0; i < dataBNov.length; i++) {
document.write(dataBNov[i]);
}
}
/*---------- BASE DATOS INDICE -------------------------------*/
function dbInd(iautor, iarticulo) {
this.iautor = iautor;
this.iarticulo = iarticulo;
this.toString = format_dbIndice;
}
/*-----------FORMATO INDICE -------------------*/
function format_dbIndice() {
text = "<SPAN CLASS='inautor'>" + this.iautor + " <\/SPAN><SPAN CLASS='inarticulo'>" + this.iarticulo;
text += "<\/SPAN><BR><P>";
return text;
}
/*-----------CARGA INDICE ----------------------------------*/
function cargaIndice(cod) {
cod= this.ncodigo;
alert(this.ncodigo);
parent.ruta = new String ("/indices/XXX.js");
parent.ruta = parent.ruta.replace("XXX",cod)
/* alert(parent.ruta);*/
indiWindow.document.write('<script language="JavaScript" SRC="' + parent.ruta + '"><\/script>');
}
/*-----------PINTA INDICE -------------------------------------*/
function printIndice(codLibro) {
for (var i=0; i < dataBInd.length; i++) {
indiWindow.document.write(dataBInd[i]);
}
}
/*---------- VENTANA INDICE -------------------------------*/
function IndiceWindow(cod){
indiWindow = window.open('', 'indWin', 'toolbar=no,location=no,scrollbars=yes,resizable=yes,width=300,height=300,left=465,top=190');
with (indiWindow.document) {
open();
write("<HTML><HEAD><TITLE>Indice<\/TITLE>");
write("<link REL=\"stylesheet\" TYPE=\"text\/css\" HREF=\"\.\.\/css\/estilo.css\">");
/* write("<SCRIPT id=\"comprueba\" LANGUAGE=\"JavaScript\" SRC=\"\.\.\/indices\/853317.js\"><\/SCRIPT>");*/
cargaIndice(cod)
write("<\/HEAD><body onLoad=" + cargaIndice(cod) + " bgcolor =" + parent.colorin+ ">");
/* alert(" base datos: " + indiWindow.document.all.comprueba.getAttribute('SRC','false'));*/
printIndice(parent.ruta);
write("<\/BODY><\/HTML>");
close();
indiWindow.focus()
}
}
Everything is going right except the loading of a new SRC.
I cannot see what is wrong!!
beetle
11-18-2002, 04:17 AM
I've seen several posts with a workaround for writing script tags....goes like this...
indiWindow.document.write('<scr'+'ipt language="JavaScript" SRC="' + parent.ruta + '"><\/scr'+'ipt>');
Weird huh? Supposed to work...
pilla
11-18-2002, 07:00 PM
Thanks a lot, I have tried it, but there must be something else wrong with my code, because it doesn't work yet. ???
pilla
11-21-2002, 03:50 PM
I think the problem is that I cannot find the way of passing the value of this.ncodigo from function dbNovs() to function printIndice().
Can anyone help me?
pilla
12-03-2002, 10:05 PM
I know this script is very long, and I have tried to resume it in only one page. What is wrong with it? Anybody knows? :confused:
MAIN PAGE
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.51 [es] (Win98; I) [Netscape]">
<title>Main</title>
<script LANGUAGE="JAVASCRIPT">
<!-- Hide
/*----1 - BOOKS DATA BASE ---*/
codLibro = ""
dataBNov = new Array(
new dbNovs("1","CD-ROM","LOPEZ MULLOR, A. Y OTROS","LA PRIMERA VILANOVA. L'ESTABLIMENT IBERIC I LA VIL.LA ROMANA D'ARRO, DARRO O ADARRO DE VILANOVA I LA GELTRU. SINTESI DELS RESULTATS DE LES DARRERES RECERQUES ARQUEOLOGIQUES I HISTORIQUES","","1992"," 93","FIGURAS","","","9,02","84-86933-21-8",""),
new dbNovs("2","","LOPEZ MULLOR, A. Y OTROS","ARQUEOLOGIA, HISTORIA I ART DE L'ESGLESIA DE SANT VALENTI DE LES CABANYES","","1992"," 134","FIGURAS","","","10,82","84-86933-25-0","Indice"),
new dbNovs("853317","","CEBRIA, A./M.R. SENABRE/J. SOCIAS","PERE GIRO I ROMEU (1894-1987). VALORACIO D'UNA FIGURA CLAUDE L'ARQUEOLOGIA PENEDESENCA","","1997"," 55","FIGURAS","","","4,81","84-86933-46-3","Indice"),
new dbNovs("333","","","EL ORO DE AMERICA/ THE GOLD OF AMERICA. EXPOSICION UNIVERSAL SEVILLA, 1992. PLAZA DE AMERICA","","1992"," 189","MUCHAS FIGS.","","","20,49","84-86925-73-8","")
);
function dbNovs(codigo, soporte, autor, titulo, ampl, ano, paginas, anex1, anex2, anex3, euros, isbn, indice) {
this.codigo = codigo;
// codLibro = codigo;
this.soporte = soporte;
this.autor = autor;
this.titulo = titulo;
this.ampl = ampl;
this.ano = ano;
this.paginas = paginas;
this.anex1 = anex1;
this.anex2 = anex2;
this.anex3 = anex3;
this.euros = euros;
this.isbn = isbn;
this.indice = indice;
this.toString = format_dbNovs;
}
/*---- 2- FORMAT BOOKS DATA -----*/
function format_dbNovs() {
text= "<tr><td>" + this.autor + "<\/td><td><\/td><td><\/td><\/tr>";
text += "<tr><td>" + this.titulo + this.ampl + "<br> " + "<\/td><td CLASS='soporte'>" + this.soporte + "<\/td><td><\/td><\/tr>";
text += "<tr><td>" + this.ano + " - " + this.paginas + " pp. - " + this.anex1.toLowerCase() + " - " + this.anex2.toLowerCase() + " - " + this.anex3.toLowerCase() + " ";
// text += '<a href=' + '../indices/' + this.codigo + '.js' + '>' + this.indice + '<\/a><\/td>'; // GOOD FOR REACHING THE FILE, BUT I O NOT WANT THE BROWSER TO OPEN IT
text += '1st try' + this.indice.link('../indices/' + this.codigo + '.js') + "<\/td>"; // 1 - GOOD FOR REACHING THE FILE, BUT I O NOT WANT THE BROWSER TO OPEN IT
text += '<td nowrap>2nd try <a href="JavaScript:IndiceWindow(this.codigo)">' + this.indice + '<\/a><\/td>'; // 2 - WHY HAVE NOT this.codigo HERE THE VALUE I SUPPOSE IT MUST HAVE?
text += '<td nowrap>3d try <a href="JavaScript:IndiceWindow(853317)">' + this.indice + '<\/a><\/td>'; // 3 - WHY with the given parameter (853317) the IndiceWindow does not load the correct SRC?
text += "<td>€ " + this.euros + "<br> <\/td><td><\/td><\/tr>";
text += "<tr><td bgcolor='#FFFAF0'> <\/td><td bgcolor='#FFFAF0'> <\/td><td bgcolor='#FFFFFF'> <\/td><\/tr>";
return text;
}
/*---- 3 - WRITE BOOKS DATA ----*/
function printNove() {
for (var i=0; i < dataBNov.length; i++) {
document.write(dataBNov[i]);
}
}
/*--- 4 - TABLE CONTENTS DATA BASE-----*/
function dbInd(iautor, iarticulo) {
this.iautor = iautor;
this.iarticulo = iarticulo;
this.toString = format_dbIndice;
}
/*----5 - FORMAT TABLE CONTENTS ----*/
function format_dbIndice() {
text = "<SPAN CLASS='inautor'>" + this.iautor + " <\/SPAN><SPAN CLASS='inarticulo'>" + this.iarticulo;
text += "<\/SPAN><BR><P>";
return text;
}
/*----- 6 - WRITE TABLE CONTENTS ---------*/
function printIndice() {
for (var i=0; i < dataBInd.length; i++) {
indiWindow.document.write(dataBInd[i]);
}
}
/*--- 7 - TABLE CONTENTS WINDOW ---*/
function IndiceWindow(codLibro) { //KEY, DOES NOT RECEIVE ANY VALUE FROM javascript:IndiceWindow(codLibro)
path = new String("../indices/XXX.js");
path = path.replace("XXX",codLibro);
alert(path);
/*----- LOAD SRC ------*/
function cargaIndice(path) {
alert(path);
indiWindow.document.write("<scr" + "ipt language='JavaScript1.2' TYPE='text/javascript'><!--");
indiWindow.document.write("<scr" + "ipt language='JavaScript1.2' SRC='" + path + "' TYPE='text/javascript'>" + "//--><\/scr" + "ipt>");
}
indiWindow = window.open('', 'indWin', 'toolbar=no,location=no,scrollbars=yes,resizable=yes,width=300,height=300,left=465,top=190');
with (indiWindow.document) {
open();
write('<HTML><HEAD><TITLE>' + path + '<\/TITLE>');
// write('<scr' + 'ipt language="JavaScript" TYPE="text/javascript" SRC="../indices/indice.js"><\/scr' + 'ipt>'); // indice.js LOADS path, DOES NOT WORK
cargaIndice(path);
// write('<scr' + 'ipt language="JavaScript" SRC="../indices/853317.js"><\/scr' + 'ipt>');
write('<\/HEAD><body bgcolor ="' + '#666666' + '">');
printIndice();
write('<\/BODY><\/HTML>');
close();
indiWindow.focus()
}
}
// End hiding-->
</script>
<!---
<script id="origInd" LANGUAGE="JavaScript" SRC="../indices/853317.js"></script>
// ---> IF NOT COMMENTED, THIS IS WHAT IndiceWindow SHOWS
</head>
<body bgcolor="#FFFFFF" MARGINHEIGHT="0" TOPMARGIN="0">
<table BORDER=0 CELLSPACING=5 CELLPADDING=0 WIDTH="85%" >
<script LANGUAGE="JavaScript"><!--
printNove();
//-->
</script>
External 853317.js
dataBInd = new Array(
new dbInd("853317"," - TABLE OF CONTENTS"),
new dbInd("V. Norskov:","Greek vases for sale: some statistical evidence"),
new dbInd("P. Lazrus:","Walking a fine Line: promoting the past without selling it"),
new dbInd("P. J. Boylan:","The concept of cultural protection in times of armed conflict: from the crusades to the new millennium"),
new dbInd("S. Dromgoole:","Law and the underwater cultural heritage: a question of balancing interests"),
new dbInd("P. J. O'Keefe:","Negotiating the future of the underwater cultural heritage"),
new dbInd("K. D. Politis:","Dealing with the dealers and tomb robbers: the realities of the archaeology of the Ghor es-Safi in Jordan"),
new dbInd("S. K. Pachauri:","Plunder of cultural and art treasures - the indian experience"),
new dbInd("K. W. Tubb:","Point, counterpoint.")
);
If you need more explanations please tell me.
Any help would be appreciated.
Pilla :)
beetle
12-03-2002, 10:13 PM
function cargaIndice(path) {
alert(path);
indiWindow.document.write("<scr" + "ipt language='JavaScript1.2' TYPE='text/javascript'><!--");
indiWindow.document.write("<scr" + "ipt language='JavaScript1.2' SRC='" + path + "' TYPE='text/javascript'>" + "//--><\/scr" + "ipt>");
}
Should be changed tofunction cargaIndice(path) {
var s = document.createElement("script");
s.setAttribute("type","text/javascript");
s.setAttribute("src",path);
document.getElementsByTagName("head")[0].appendChild(s);
}
pilla
12-03-2002, 10:46 PM
Thaaaaaannnksss, Beettle! :thumbsup:
thank you very much, that would solve one of the two problems I've got with this script.
The other one is: what am I doing wrong with the value (this.codigo) I need to pass from the list of books to the "path"?
This can be obvious for you but not for a newbie like me, so please, please.... help me and my brain.
Pilla :)
glenngv
12-04-2002, 02:03 AM
text += '<td nowrap>2nd try <a href="javascript:IndiceWindow(\''+this.codigo+'\')">' + this.indice + '<\/a><\/td>';
pilla
12-09-2002, 12:50 AM
Thanks a million, Glenn, I had not noticed the missing '. How stupid I am!
Now the script works well :thumbsup: in IE, but not in Netscape 7. It is a bit strange, it seems as if Netscape do not read the external data the first time but the second one. Could this be possible? :confused:
Perhaps is there any other error?
Perhaps should I change the idea of pop up window for a layer??
Any suggestions??
Pilla :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.