ericworldz
asked on
open a new window with javascript
This is what I have to open a new window:
<%@include file="/site/includes/secur e.jsp"%>
<!--%@include file="/site/includes/check login.jsp" %-->
<Script>
<!--
window.open('Annual_Report _c_r.pdf', '','width= 800,height =600,toolb ar=1,locat ion=0,dire ctories=0, status=1,m enubar=1,s crollbars= 1,resizabl e=1');
window.history.go(-2);
//-->
</Script>
The problem is when it first open, there would be 2 pdf window open at once. The second time I open it, then it will open normally. How can I fix this?
Thanks!
<%@include file="/site/includes/secur
<!--%@include file="/site/includes/check
<Script>
<!--
window.open('Annual_Report
window.history.go(-2);
//-->
</Script>
The problem is when it first open, there would be 2 pdf window open at once. The second time I open it, then it will open normally. How can I fix this?
Thanks!
what history.go(-2) is doing there!!!
ASKER
If there's no history.back(), the first window will be showing blank. If I do history.go(-1), to go back one page, the page will keep on reload, because of the <!--%@include file="/site/includes/check login.jsp" %-->
So that's why I need to go back 2 pages.
So that's why I need to go back 2 pages.
I think that history is forcing the script to run two times........
do one thing...
<!--
window.open('Annual_Report _c_r.pdf', '','width= 800,height =600,toolb ar=1,locat ion=0,dire ctories=0, status=1,m enubar=1,s crollbars= 1,resizabl e=1');
alert("test");
window.history.go(-2);
//-->
</Script>
and see how many times you see this alert.....
do one thing...
<!--
window.open('Annual_Report
alert("test");
window.history.go(-2);
//-->
</Script>
and see how many times you see this alert.....
ASKER
yes the alert message pops up twice. so how do I fix that?
do not have history,back().... beacuse it will force the HTML to load from the cache and as HTML is loading it will fire up the script...
you might put some dealy on the script so that your includes load up......and then you will not need history.back()
you might put some dealy on the script so that your includes load up......and then you will not need history.back()
ASKER
can you be more specific on how this can be done without using the window.history.go(-2)? I need the first window to display the website content also without history.back(), the first window is blank.
<!--
window.setTimeout(500);
window.open('Annual_Report _c_r.pdf', '','width= 800,height =600,toolb ar=1,locat ion=0,dire ctories=0, status=1,m enubar=1,s crollbars= 1,resizabl e=1');
//-->
</Script>
try this... it will wait for half a second before opening the pdf box.. in that much time your parent page should get loaded
window.setTimeout(500);
window.open('Annual_Report
//-->
</Script>
try this... it will wait for half a second before opening the pdf box.. in that much time your parent page should get loaded
ASKER
settimeout needs 2 arguments?
ooops my bad...........
its gonna be
<!--
window.setTimeout("myfunc" ,500);
function myfunc()
{
window.open('Annual_Report _c_r.pdf', '','width= 800,height =600,toolb ar=1,locat ion=0,dire ctories=0, status=1,m enubar=1,s crollbars= 1,resizabl e=1');
}
//-->
</Script>
its gonna be
<!--
window.setTimeout("myfunc"
function myfunc()
{
window.open('Annual_Report
}
//-->
</Script>
ASKER
The first window is still blank no matter how long the time interval is set to.
Try this:
<%@include file="/site/includes/secur
<!--%@include file="/site/includes/check
<Script>
<!--
var myWin = window.open('Annual_Report
//-->
</Script>
Javier
ASKER
Javier,
That does exact same thing besides assigning it to the variable myWin.
That does exact same thing besides assigning it to the variable myWin.
ASKER
I will have to close this question under this topic and move it to JavaScript.
whats written in your include files????
>That does exact same thing besides assigning it to the variable myWin.
Well normally when you assign the window.open to a var it always open the same window, that's why I told you tol test it, if it still opens you a new window maybe is becose of the includes.
Can you pos the jsp codes here?
Javier
Well normally when you assign the window.open to a var it always open the same window, that's why I told you tol test it, if it still opens you a new window maybe is becose of the includes.
Can you pos the jsp codes here?
Javier
ASKER
<!------------------------ ---------- checklogin .jsp------ ---------- ---------- >
<%
UID = Session("UID")
If UID="" Then
Response.Redirect "/site/content/login.jsp?u rl=" + Request.ServerVariables("S CRIPT_NAME ")
End If
%>
<%
UID = Session("UID")
If UID="" Then
Response.Redirect "/site/content/login.jsp?u
End If
%>
You picked that from and ASP??
Javier
Javier
Shouldn't it be like this:
<%
String UID =(String) session.getAttribute("UID" )
If (UID==null || UID.equals("")) {
response.sendRedirect("/si te/content /login.jsp ?url=" + request.getHeader("SCRIPT_ NAME"))
}
%>
Javier
<%
String UID =(String) session.getAttribute("UID"
If (UID==null || UID.equals("")) {
response.sendRedirect("/si
}
%>
Javier
Sorry:
<%
String UID =(String) session.getAttribute("UID" )
If (UID==null || UID.equals("")) {
response.sendRedirect("/si te/content /login.jsp ?url=" + request.getServletPath());
}
%>
Javier
<%
String UID =(String) session.getAttribute("UID"
If (UID==null || UID.equals("")) {
response.sendRedirect("/si
}
%>
Javier
Anyway that shouldn't open a new window, is this all your JSP code?
ASKER
yes
Yes What?
You can't include an ASP to a JSP.
Javier
You can't include an ASP to a JSP.
Javier
ASKER
okay here's what i did to resolve the problem:
window.location = 'Annual_Report_c_r.pdf';
window.location = 'Annual_Report_c_r.pdf';
but this will not open up a new window...., it will open the PDF in the same window.....
Well I guess is been a missundertood, becose it wasn't opening 2 windows but keeping the opener one opened so this could worked to:
<%@include file="/site/includes/secur e.jsp"%>
<!--%@include file="/site/includes/check login.jsp" %-->
<Script>
<!--
window.open('Annual_Report _c_r.pdf', '','width= 800,height =600,toolb ar=1,locat ion=0,dire ctories=0, status=1,m enubar=1,s crollbars= 1,resizabl e=1');
window.close();
//-->
</Script>
Javier
<%@include file="/site/includes/secur
<!--%@include file="/site/includes/check
<Script>
<!--
window.open('Annual_Report
window.close();
//-->
</Script>
Javier
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.