Link to home
Start Free TrialLog in
Avatar of ericworldz
ericworldz

asked on

open a new window with javascript

This is what I have to open a new window:

<%@include file="/site/includes/secure.jsp"%>
<!--%@include file="/site/includes/checklogin.jsp"%-->
<Script>
<!--
window.open('Annual_Report_c_r.pdf','','width=800,height=600,toolbar=1,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=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!
Avatar of Kuldeepchaturvedi
Kuldeepchaturvedi
Flag of United States of America image

what history.go(-2) is doing there!!!
Avatar of ericworldz
ericworldz

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/checklogin.jsp"%-->

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,toolbar=1,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1');
alert("test");
window.history.go(-2);
//-->
</Script>
and see how many times you see this alert.....
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()
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,toolbar=1,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=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
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,toolbar=1,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1');
}
//-->
</Script>
The first window is still blank no matter how long the time interval is set to.

Try this:

<%@include file="/site/includes/secure.jsp"%>
<!--%@include file="/site/includes/checklogin.jsp"%-->
<Script>
<!--
var myWin = window.open('Annual_Report_c_r.pdf','','width=800,height=600,toolbar=1,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1');
//-->
</Script>

Javier
Javier,
That does exact same thing besides assigning it to the variable myWin.
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
<!----------------------------------checklogin.jsp-------------------------->
<%
      UID = Session("UID")
      If UID="" Then
            Response.Redirect "/site/content/login.jsp?url=" + Request.ServerVariables("SCRIPT_NAME")
      End If
%>
You picked that from and ASP??
Javier
Shouldn't it be like this:
<%
     String UID =(String)  session.getAttribute("UID")
     If (UID==null || UID.equals("")) {
          response.sendRedirect("/site/content/login.jsp?url=" + request.getHeader("SCRIPT_NAME"))
     }
%>

Javier
Sorry:

<%
     String UID =(String)  session.getAttribute("UID")
     If (UID==null || UID.equals("")) {
          response.sendRedirect("/site/content/login.jsp?url=" + request.getServletPath());
     }
%>

Javier
Anyway that shouldn't open a new window, is this all your JSP code?
yes
Yes What?
You can't include an ASP to a JSP.
Javier
okay here's what i did to resolve the problem:
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/secure.jsp"%>
<!--%@include file="/site/includes/checklogin.jsp"%-->
<Script>
<!--
window.open('Annual_Report_c_r.pdf','','width=800,height=600,toolbar=1,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1');
window.close();
//-->
</Script>

Javier
ASKER CERTIFIED SOLUTION
Avatar of Lunchy
Lunchy
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial