Solved

open a new window with javascript

Posted on 2004-04-02
28
920 Views
Last Modified: 2010-05-18
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!
0
Comment
Question by:ericworldz
  • 10
  • 8
  • 7
  • +2
28 Comments
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10743994
what history.go(-2) is doing there!!!
0
 

Author Comment

by:ericworldz
ID: 10744060
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.
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10744084
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.....
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:ericworldz
ID: 10744213
yes the alert message pops up twice. so how do I fix that?
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10744236
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()
0
 

Author Comment

by:ericworldz
ID: 10744566
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.
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10744610
<!--
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
0
 

Author Comment

by:ericworldz
ID: 10744683
settimeout needs 2 arguments?
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10744692
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>
0
 

Author Comment

by:ericworldz
ID: 10744838
The first window is still blank no matter how long the time interval is set to.
0
 

Expert Comment

by:fks2
ID: 10746709
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10756421

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
0
 

Author Comment

by:ericworldz
ID: 10756626
Javier,
That does exact same thing besides assigning it to the variable myWin.
0
 

Author Comment

by:ericworldz
ID: 10756634
I will have to close this question under this topic and move it to JavaScript.
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10756829
whats written in your include files????
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10757075
>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
0
 

Author Comment

by:ericworldz
ID: 10757117
<!----------------------------------checklogin.jsp-------------------------->
<%
      UID = Session("UID")
      If UID="" Then
            Response.Redirect "/site/content/login.jsp?url=" + Request.ServerVariables("SCRIPT_NAME")
      End If
%>
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10757133
You picked that from and ASP??
Javier
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10757167
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
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10757186
Sorry:

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

Javier
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10757229
Anyway that shouldn't open a new window, is this all your JSP code?
0
 

Author Comment

by:ericworldz
ID: 10757643
yes
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10757654
Yes What?
You can't include an ASP to a JSP.
Javier
0
 

Author Comment

by:ericworldz
ID: 10757965
okay here's what i did to resolve the problem:
window.location = 'Annual_Report_c_r.pdf';
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10758005
but this will not open up a new window...., it will open the PDF in the same window.....
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10758023
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
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 10798160
Closed, 50 points refunded.
Lunchy
Friendly Neighbourhood Community Support Moderator
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Reading data  from excel sheet and displaying 1 82
countXY challenge 28 150
JavaScript parse form with colon separated values 2 77
jsp login check 12 28
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question