|
 |
Javascript How-To Ask your "How do I do this with Javascript?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|
 |
|

September 27th, 2004, 01:22 PM
|
Friend of Wrox
|
|
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi Elisabeth,
When you set a function to be called with setTimeout(), it get's called in the context of the current window, not where you originally set it in your code, therefore any variables / methods etc you want to access at that point need to be globally available.
Best regards,
Chris
|

September 27th, 2004, 01:36 PM
|
Authorized User
|
|
Join Date: Feb 2004
Location: , , .
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well, the problem is that it does not entirely work.
If I click on the first help field (that would call the explain functio), the 1st popup page appears.
Now, I click on the 2nd help field (which is longer than the first one, so I call the explain1 function).
RESULT: Only one of the two popup pages is automatically closed.!!!
Listen, I have defined 2 help popup pages (I am sure there is a better way of doing it but I don't know it). The reason I have done that is that I need the message to fit the popup page.... so I have defined 2 identical popup pages with 2 different heights!.
Now, here is what I have:
<script....>
var newwin;
var newwin1;
function explain(msg)
{
newwin = window.open('', 'popUp1',"top=150,left=150,height=180,width=325,lo cation....setTimeout('newwin.close()', 60000);
newwin.focus();
....
}
function explain1(msg)
{
newwin1 = window.open('', 'popUp1',"top=150,left=150,height=180,width=325,lo cation....
setTimeout('newwin1.close()', 60000);
newwin1.focus();
...
}
|

September 27th, 2004, 01:41 PM
|
Authorized User
|
|
Join Date: Feb 2004
Location: , , .
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Actually it is always newwin that is automatically closed!
|

September 27th, 2004, 02:58 PM
|
Authorized User
|
|
Join Date: Feb 2004
Location: , , .
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Do you know what could be wrong?
|

September 28th, 2004, 04:40 AM
|
Friend of Wrox
|
|
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
What you posted works fine for me, but you may want to give the windows different names - at the moment they are both called "popUp1", so if the first window is open when the second function is called or vice versa, the window will get reused & the different sizes you want will get ignored.
If it's still not working, can you post your entire code please?
Cheers,
Chris
|

September 28th, 2004, 05:54 AM
|
Authorized User
|
|
Join Date: Feb 2004
Location: , , .
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here is the story.
I have a file that contains fields. Next to each field, I have a link (referes to help.jsp) that once is clicked popups a window with the field definition.
Due to the fact that some messages are longer than others, I need different popup windows. For this reason, I have a another link that referes to help1.jsp
Because I use those files quite often, I add them as "include files".
The same thing happens with the popup windows javascript functions. I know I should use a proper javascript library but for the moment I am using a "include of javascriptLib.html". javascripLib.html contains javascript scripts.
Here it goes:
file.jsp that contains the fields and the links to help.
<form action="add_service.jsp" method=post>
<table>
<tbody>
<tr>
<td>Service label:</td>
<td><input type=text tabindex=1 name="serv_lab"></td>
<%
String msg="\'"+(String)id.getHelp("service_label")+"\'";
<tr>
<td>Conexions:</td>
<td><input type=text tabindex=1 name="conn"></td>
<%
msg="\'"+(String)id.getHelp("conn")+"\'";
%>
<%@ include file="../includes/help1.jsp"%>
<%@ include file="../includes/help.jsp"%>
help.jsp contains:
<td><a href="javascript:explain(<%=msg%>);" onMouseOver="window.status='Expl...';return true;" onMouseOut="window.status='';return true;"><img src=".
./img/question.gif" ></a> </td>
help1.jsp contains
<td><a href="javascript:explain1(<%=msg%>);" onMouseOver="window.status='Expl...';return true;" onMouseOut="window.status='';return true;"><img src=".
./img/question.gif" ></a> </td>
javascriptLib.html contains
<script language="JavaScript">
javascript:window.history.forward(1);
var newwin;
var newwin1;
......function explain(msg)
{
newwin = window.open('', 'popUp',"top=150,left=150,height=110,width=325,loc ation
=no,scrollbars=no,menubars=no,toolbars=no,resizabl e=no, menubar=no");
newwin.focus();
setTimeout('newwin.close()', 10000);
if (!newwin.opener) newwin.opener = self;
with (newwin.document)
{
open();
write('<html>');
write('<body onLoad="document.form.box.focus()"><form name=form>' + msg + '<br>'
);
write('<p><center><input type=button value="Cerrar ventana" onClick=window.close
()>');
write('</center></form></body></html>');
close();
}
} function explain1(msg)
{
newwin1 = window.open('', 'popUp1',"top=150,left=150,height=180,width=325,lo cati
on=no,scrollbars=no,menubars=no,toolbars=no,resiza ble=no, menubar=no");
setTimeout('newwin1.close()', 60000);
newwin1.focus();
if (!newwin1.opener) newwin1.opener = self;
with (newwin1.document)
{
open();
write('<html>');
write('<body onLoad="document.form.box.focus()"><form name=form>' + msg + '<br>'
);
write('<p><center><input type=button value="Cerrar ventana" onClick=window.close
()>');
write('</center></form></body></html>');
close();
}
}
Hope that helps.
|

September 28th, 2004, 12:03 PM
|
Friend of Wrox
|
|
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi Elisabeth,
I expanded your code to get
Code:
<html>
<head>
<title></title>
</head>
<body>
<form action="add_service.jsp" method=post>
<table>
<tbody>
<tr>
<td>Service label:</td>
<td><input type=text tabindex=1 name="serv_lab"></td>
<tr>
<td>Conexions:</td>
<td><input type=text tabindex=1 name="conn"></td>
<td><a href="javascript:explain('some message');" onMouseOver="window.status='Expl...';return true;" onMouseOut="window.status='';return true;"><img src=".
./img/question.gif" ></a> </td>
<td><a href="javascript:explain1('some other message');" onMouseOver="window.status='Expl...';return true;" onMouseOut="window.status='';return true;"><img src=".
./img/question.gif" ></a> </td>
<script language="JavaScript">
javascript:window.history.forward(1);
var newwin;
var newwin1;
function explain(msg)
{
newwin = window.open('', 'popUp',"top=150,left=150,height=110,width=325,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no, menubar=no");
newwin.focus();
setTimeout('newwin.close()', 10000);
if (!newwin.opener) newwin.opener = self;
with (newwin.document)
{
open();
write('<html>');
write('<body onLoad="document.form.box.focus()"><form name=form>' + msg + '<br>');
write('<p><center><input type=button value="Cerrar ventana" onClick=window.close()>');
write('</center></form></body></html>');
close();
}
}
function explain1(msg)
{
newwin1 = window.open('', 'popUp1',"top=150,left=150,height=180,width=325,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no, menubar=no");
setTimeout('newwin1.close()', 10000);
newwin1.focus();
if (!newwin1.opener) newwin1.opener = self;
with (newwin1.document)
{
open();
write('<html>');
write('<body onLoad="document.form.box.focus()"><form name=form>' + msg + '<br>');
write('<p><center><input type=button value="Cerrar ventana" onClick=window.close()>');
write('</center></form></body></html>');
close();
}
}
</script>
</body>
</html>
And both windows close fine. You get an error in each caused by "document.form.box.focus()", but that's because theres no "box" element in your form.
Best regards,
Chris
|

September 28th, 2004, 01:03 PM
|
Authorized User
|
|
Join Date: Feb 2004
Location: , , .
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
OK, I will see what is wrong then when I use includes.
Thanks for your help. I will try it out tomorrow and will come back to you.
|

January 29th, 2017, 02:34 AM
|
Friend of Wrox
|
|
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
|
|
Ok.. this is not for the forum this post and I am sorry... I tried creating a new thread with no success (not sure why, guess I am not a paying member if their is such a thing...didn't thing there was). I have come to this site and actually started my "coding forum" experience on this site. I have bought several books and have found them extremely valuable...could almost be deemed a necessity in the academia. However THIS SITE HAS GOT OLD VERRRRRY OLD AND TIRED and it shows almost no one posts,or at least my screen shows it, and this site has the look and feel of a 1990's application . Lets update the look and feel, the technology behind it, and possibly write a book on it. ALSO FIX THE LOGIN BUGS. surely I am not the only one to have experienced them.
I apologize if I am being brash but I like this site and the wrox books, and it needs to change with the times.
|

January 29th, 2017, 02:43 AM
|
Friend of Wrox
|
|
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
|
|
Ok.. this is not for this forum/post and I am sorry... I tried creating a new thread with no success (not sure why, guess I am not a paying member if their is such a thing..didn't think there was). I have come to this site and actually started my "coding forum" experience on this site. I have bought several books and have found them extremely valuable...could almost be deemed a necessity in the academia. However, THIS SITE HAS GOTTEN OLD AND VERRRRRY TIRED; and it shows, almost no one posts or at least my screen shows it...this site has the look and feel of a 1990's application. Lets update it...maybe using the technology described most here in/. Possibly write a book on it. ALSO FIX THE LOGIN BUGS. surely I am not the only one to have experienced them.
JUST don't update it with a 10 year old look/feel as well as 20 year old backend like my company did.
I apologize if I am being brash but I like this site and the wrox books, and it needs to change with the times.
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |