Solved

open a new window with javascript

Posted on 2004-04-02
28
926 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
Independent Software Vendors: 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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
how to exclude a file using regex 5 123
excpetion with multiple catch 11 139
ejb on wildfly 5 61
mysql jsp example issue 32 94
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

737 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