Solved

Pop up a new window - Javascript, window.open and <a target="_blank"

Posted on 2002-06-05
48
768 Views
Last Modified: 2011-10-03
I want to pop up a new window.

I am doing it with 2 different ways as per my requirements. I use, <a target="_blank", where i used link, and i use, onlick="window.open()" when i use it with button.

Link - <a target="_blank" href="URL">
Button - <input type="Button" onclick="window.open("URL");">

The link option is working fine. But the button is not working. I know, there wont be any problem with Link or Burron onClick.

Now, the URL is to download a file from server. So, when the new window is opened by Link, it works fine. So, there wont be any problem in downloading the file from server. But, if i open the same URL with Button using window.open, then it gives error as following while downloading the file. The error is as following.

Internet Explorer can not download URL from SERVER.

So, can anybody please give me the solution or alternative way to do it.

Thankx
0
Comment
Question by:mauliknaik
  • 18
  • 8
  • 7
  • +6
48 Comments
 
LVL 12

Expert Comment

by:lexxwern
ID: 7055759
i see you've used double quotes at 2 places...try this...


Button - <input type="Button" onclick="window.open('URL');">
0
 
LVL 30

Expert Comment

by:third
ID: 7055788

it should be

<input type="Button" onclick="window.open(URL);">

without the quotes
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7055793
single quotes in double quotes should work...

no?
0
 
LVL 30

Expert Comment

by:third
ID: 7055795

p.s.

where URL is a global javascript variable that contains the link to the file.

<script>
  var URL = 'http://foo.com/foo.zip';
</script>

when you mean that the URL is the actual link then

<input type="button" onclick="window.open('http://foo.com/foo.zip')";>

will be correct.
0
 
LVL 30

Expert Comment

by:third
ID: 7055797
i thought URL is a variable. 'URL' is not a good example on this situation. ;-(
0
 

Author Comment

by:mauliknaik
ID: 7055805
Thankx for all these comments.

But, as I saied in the Question, i know there is not the problem of Javascript window.open(), I used URL in general form to show that, i used the same URL in both <a href="URL" target="_blank"> and in <input type="button" onclick="window.open('URL')">.

So, no problem of single quote or double quote.

Thankx.
0
 

Author Comment

by:mauliknaik
ID: 7055816
Thankx for all these comments.

But, as I saied in the Question, i know there is not the problem of Javascript window.open(), I used URL in general form to show that, i used the same URL in both <a href="URL" target="_blank"> and in <input type="button" onclick="window.open('URL')">.

So, no problem of single quote or double quote.

Thankx.
0
 
LVL 5

Expert Comment

by:kcm76
ID: 7055821
0
 
LVL 30

Expert Comment

by:third
ID: 7055832
"Internet Explorer can not download URL from SERVER."

i have encountered this problem once but the only reason it generates such error because i made a typo. could you double check it?

or if possible, give us the link of the page you are working on so we can also test and give you a much accurate answer.

0
 

Author Comment

by:mauliknaik
ID: 7055840

Hi KCM,

Thankx for the link you provided.

But, It says to open a new window to download the file using 3 options. I am using 2 of them. (the HREF tag contains "target=_blank" and window.open() ). But, the problem is, it works fine for "targer=_blank" and it is not working for window.open()..

HI Thrid,

I am using same URL for both options, so, it is not possible in URL mistake. Then also, I rechecked it.

The url is as following.

download.cfm?file_id=1234567

Thankx
0
 
LVL 30

Expert Comment

by:third
ID: 7055850
assuming you have this download.cfm try,

<a href="test" onclick="window.open('download.cfm?file=1234567');return false;">test</a>

or

<a href="javascript:window.open('download.cfm?file=1234567');">test</a>

and give us feedback on what happened.
0
 

Author Comment

by:mauliknaik
ID: 7055857
It is giving the same problem.

I concluted that, this problem occurs with window.open().

e.g.

if i use,
<a href="test" onclick="window.open('download.cfm?file=1234567');return false;">test</a>,
then it dosent work.

and also, if i use,
<input type="button" onclick="window.open('download.cfm?file=1234567');return false;">,
then also it dosent work.

See, if i use <a target="_blank" or window.open, anyway, it is opeaning a new instance of IE. So, why does it give the problem in these 2 different methods.
0
 
LVL 5

Expert Comment

by:kcm76
ID: 7055884
Have u gone thru the workaround provided in that link?
0
 
LVL 14

Expert Comment

by:avner
ID: 7055900
mauliknaik,
window.open() is widley used and is part of the basic functionallty of IE.
if you do encouter some problems it's because of some typos you have or a wrong syntax.
Try to paste your exact code and see where is your mistake, you can use this example to verify that a different url does work :

<a href="test" onclick="window.open('http://www.experts-exchange.com/javascript/Q_20307983.html');return false;">test using link</a>,
<input type="button" onclick="window.open('http://www.experts-exchange.com/javascript/Q_20307983.html');return false;" value="test button">

Both of these examples works.

-avner
0
 

Author Comment

by:mauliknaik
ID: 7055911

Hello  KCM,

yaa, i have gone through that, but that page talks about the browser window (first window) closes after downloading the file. Whis is not my problem.

Workaround gives solutions to keep the primary window open, and that is not my problem.
0
 

Author Comment

by:mauliknaik
ID: 7056002

hello avner,

you are right. It works for both the links. But, as i told above, the URL is not a normal HTML page. It is a ColdFusion Page, which gives the download file option.

Here with i am giving my code.

Following works fine.

<a target="_blank" href="http://www.foo.com/index.cfm?fuseaction=modules.docman.dsp_read_file&file_uid=123456">Download File</a>

followingdosentwork.

<input type="Button" value="Download File"  onclick="window.open('http://www.foo.com/index.cfm?fuseaction=modules.docman.dsp_read_file&file_uid=123456');">

I hope,this can help u out.

Thankx
0
 
LVL 14

Expert Comment

by:avner
ID: 7056014
Well, I was trying these links, both returns a 404 page ( I assume it's not a real URL) but in both cases I do get the new web-browser to open up, so the question here is what behavior do you encounter with the real url ?
0
 

Author Comment

by:mauliknaik
ID: 7056040
Anvar,

Ofcourse it is not a real URL. The host name is local, so i gave www.foo.com.

and yes, in both the cases u will get new browsers.

So, i am opeaning ColdFusion File in new window, and that ColdFusion file will Download File.

Now, it is working fine with target="_blank", but, it is not working for window.open().


So, the problem is, when i try to download a file with window.open(), it dosent work.

0
 
LVL 14

Expert Comment

by:avner
ID: 7056051
Ok, I think I'm starting to get the picture.
Both cases loads the CFM currectly, but with window.open() wehn you submit the download-file script it dosen't work right ?
0
 

Author Comment

by:mauliknaik
ID: 7056062
Anvar,

You got it right.

I described above how i used both way.

0
 
LVL 11

Expert Comment

by:mouatts
ID: 7056668
Is there a space between 'dsp read file' just if there is try replacing it with a + symbol.

Steve
0
 
LVL 19

Expert Comment

by:webwoman
ID: 7057585
Use this
<a href="#" onclick="window.open('download.cfm?file=1234567');return false;">test</a>,

It's most certainly NOT going to work if you have "test" in the a href -- you don't have a file/page called "test" do you?

The # is the standard dummy link -- it goes nowhere.
0
 
LVL 30

Expert Comment

by:third
ID: 7058001

ww,

   im sorry the href="test" was a typo on my part. My bad.

 
0
 
LVL 30

Expert Comment

by:third
ID: 7058041
can you create a .html file instead of .cfm so we can test again.


test.html
----------------

<html>
<body>
  <a href="test.html?file=1234567.1.2" target="_blank">test</a>
  <input type="button" onclick="window.open('test.html?file=1234567.1.2')">
  <a href="#" onclick="window.open('test.asp?file=1234567.1.2');return false;">test</a>
  <a href="javascript:window.open('test.asp?file=1234567.1.2');" target="_blank">test</a>
</body>
</html>

kindly test each of this links/button and give us feedback.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:mauliknaik
ID: 7058807
Hello Mouatts,

there is no space, it is underscore (_) .. and it is covered with Link, so , its not visibal.

Hello Webwomen,

You are right, 'test' dont work. But, that is not the problem.

See, guyz, i know that, there is no probolem in opeaning a new window using any of the method. (<a target="_blank" and window.open()) .. but, the new opened URL is to download a file. Which is a webscript file. which can not be any HTML file. Because, it generates output dynamically. So, there is no problem in opeaning any static HTML page. or also even any normal CFM page. But the problem is, when i open a new CFM page, which is to download a file. It dosent work.

Thankx
0
 
LVL 11

Expert Comment

by:mouatts
ID: 7058891
Can you turn off 'show friendly error messages' and let us know what error you get.
0
 
LVL 19

Expert Comment

by:webwoman
ID: 7061091
Well, of course it won't work if it's a download. You don't even NEED To open a new window, or a blank, or ANYTHING if it's a download. A standard link will work.

A download doesn't take you anywhere -- it opens a DOWNLOAD prompt. That's what it's supposed to do.

Make a normal link.
0
 

Author Comment

by:mauliknaik
ID: 7061123
Hi Webwomen,

Please refer the link below, which is provided by KCM above. It says, after completion of downloadm it closes the main window.

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q268976
0
 
LVL 19

Expert Comment

by:webwoman
ID: 7061179
I've never had a download link close the main window. Has anybody here had that happen?

Have you tried it as a regular link?

Because if I'm reading that link right, the reason it's acting up is because you're trying to open it in a new window -- and it CAN'T open in a new window.

Did you read the solution?
>>Do not right-click a link and then click Open In A New Window . Instead, just click the link that contains the download link.>>

Make it a regular link.
0
 

Author Comment

by:mauliknaik
ID: 7061309
Hello Webwomen,

Yaa, you are right, after posting the message, i tried it again, and it worked.

But, now, i want to get the download link on a button. so, can i do it ?? or the only option is to use Link !!

Thankx
0
 
LVL 12

Accepted Solution

by:
lexxwern earned 200 total points
ID: 7061567
<input type="button" value="download" onclick="javascript: window.location='zip.zip';"/>
0
 

Author Comment

by:mauliknaik
ID: 7061573

Thankx Lexxwern.
0
 

Author Comment

by:mauliknaik
ID: 7061578

But Lexxwern,

can i refresh the main page after this ?? i mean, after forcing the browser to download file, it wont accept any other code, so i am not able to refresh the page.

thankx again
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7061579
so it worked?
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7061589
IE6 i could refresh the original page.

NS6.2 i could.

i dont know abt others. refreshing is more of a browser issue.
0
 

Author Comment

by:mauliknaik
ID: 7061597

yaa lexxwern

you can refresh the page, if u can throw code to refresh the page on the browser. But, after using code to download file, it is not doin anything, and also in View Source, its not throwin JS code to refresh the page. i am using location.href to refresh the page.
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7061618
what!!

what do u mean by throwing code?


do you want the page to refresh after a file has been downloaded?
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7061622
<input type="button" value="download" onclick="javascript: window.open('proposal.doc'); window.location='test.html';"/>
0
 

Author Comment

by:mauliknaik
ID: 7061655

window.open() was not woring, thats why i accepeted ur option of
<input type="button" value="download" onclick="javascript: window.location='zip.zip';"/>

it is giving error like as following

can not download file FileName.doc from SERVER

so, i have to use, location.href or <a href ..

but, here the probelm is, it is not returning anything to browser, ( if i want to download file, it wont output anything to browser ) ..

0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7061664
use he normal a href and create a buttons look with an image.

or

try the absolute path.


im still not sure what you want...sorry. btw im out of here for now. going to watch soccer. england v argentina.


good luck.
0
 
LVL 11

Expert Comment

by:mouatts
ID: 7061679
I repeat Can you turn off 'show friendly error messages' and let us know what error you get.
0
 

Author Comment

by:mauliknaik
ID: 7061840

Hi lexxwern,

Yaa, the image button could have been used, but, its not allows from point view of UI. Thats why i want in both way, one as Link and one as Button, at different places to call the same file.

anywayz, Njoy soccer, david beckham's gole was amezing. :)


Hello Mouatta,

The error message is as following exectly. It was same before i turned off the 'Show friendly http error messages'.

Internet explorer cannot download ... download.cfm?file_uid=1234 from server

Internet explorer was not able to open this internet site. The requested site is either unavailable or can not be found. Please try again later.

0
 
LVL 19

Expert Comment

by:webwoman
ID: 7061988
Use a graphic of a button and make a regular link.
0
 

Author Comment

by:mauliknaik
ID: 7062008

Yaa, thats the last option with some compromise. But if possible then, i am looking for good option.
0
 
LVL 11

Expert Comment

by:mouatts
ID: 7062065
Maybe its just me, but I've got lost as to what actually isn't working now. I do have one idea but I could be just deluding myself so can you post the actually code that isn't working please.
0
 

Author Comment

by:mauliknaik
ID: 7062170
Here with i am giving my code.

Following works fine.

<a target="_blank" href="download.cfm?file_uid=123456">Download File</a>

following dosent work.

<input type="Button" value="Download File"  onclick="window.open('download.cfm?file_uid=123456');">

So, I concluted that, window.open wont work to download file. And after all these discussion, i concluded that, following 2 options are working fine.

1. Link
<a href="download.cfm?file_uid=123456">Download File</a>

2. Button
<input type="button" Value="Download File" onlcick="location.href='download.cfm?file_uid=123456';">

But, the page i am calling is a CFM page, and it opens dialogbox to download file. And  at the same time, i am making some database updates, so , i want to refresh the main calling page to show updated information.

I hope this was enough to clear u the problem.

Thankx

Maulik

0
 
LVL 12

Expert Comment

by:ahosang
ID: 8275959
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

points to lexxwern
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
0
 

Expert Comment

by:modulo
ID: 8360566
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 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

14 Experts available now in Live!

Get 1:1 Help Now