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!
JSP

Avatar of undefined
Last Comment
Lunchy

8/22/2022 - Mon
Kuldeepchaturvedi

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

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.
Kuldeepchaturvedi

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.....
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER
ericworldz

yes the alert message pops up twice. so how do I fix that?
Kuldeepchaturvedi

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()
ASKER
ericworldz

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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Kuldeepchaturvedi

<!--
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
ASKER
ericworldz

settimeout needs 2 arguments?
Kuldeepchaturvedi

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>
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
ericworldz

The first window is still blank no matter how long the time interval is set to.
fks2

jarasa


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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
ericworldz

Javier,
That does exact same thing besides assigning it to the variable myWin.
ASKER
ericworldz

I will have to close this question under this topic and move it to JavaScript.
Kuldeepchaturvedi

whats written in your include files????
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
jarasa

>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
ASKER
ericworldz

<!----------------------------------checklogin.jsp-------------------------->
<%
      UID = Session("UID")
      If UID="" Then
            Response.Redirect "/site/content/login.jsp?url=" + Request.ServerVariables("SCRIPT_NAME")
      End If
%>
jarasa

You picked that from and ASP??
Javier
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
jarasa

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
jarasa

Sorry:

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

Javier
jarasa

Anyway that shouldn't open a new window, is this all your JSP code?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
ericworldz

yes
jarasa

Yes What?
You can't include an ASP to a JSP.
Javier
ASKER
ericworldz

okay here's what i did to resolve the problem:
window.location = 'Annual_Report_c_r.pdf';
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Kuldeepchaturvedi

but this will not open up a new window...., it will open the PDF in the same window.....
jarasa

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
Lunchy

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question