Solved

open a new window with javascript

Posted on 2004-04-02
28
917 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

A Short Story about the Best File Recovery Software – Acronis True Image 2017
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now