Solved

open a new window with javascript

Posted on 2004-04-02
28
927 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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