• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 838
  • Last Modified:

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

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
mauliknaik
Asked:
mauliknaik
  • 18
  • 8
  • 7
  • +6
1 Solution
 
lexxwernCommented:
i see you've used double quotes at 2 places...try this...


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

it should be

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

without the quotes
0
 
lexxwernCommented:
single quotes in double quotes should work...

no?
0
Technology Partners: 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!

 
thirdCommented:

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
 
thirdCommented:
i thought URL is a variable. 'URL' is not a good example on this situation. ;-(
0
 
mauliknaikAuthor Commented:
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
 
mauliknaikAuthor Commented:
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
 
Chandramouli kArchitectCommented:
0
 
thirdCommented:
"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
 
mauliknaikAuthor Commented:

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
 
thirdCommented:
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
 
mauliknaikAuthor Commented:
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
 
Chandramouli kArchitectCommented:
Have u gone thru the workaround provided in that link?
0
 
avnerCommented:
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
 
mauliknaikAuthor Commented:

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
 
mauliknaikAuthor Commented:

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
 
avnerCommented:
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
 
mauliknaikAuthor Commented:
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
 
avnerCommented:
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
 
mauliknaikAuthor Commented:
Anvar,

You got it right.

I described above how i used both way.

0
 
mouattsCommented:
Is there a space between 'dsp read file' just if there is try replacing it with a + symbol.

Steve
0
 
webwomanCommented:
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
 
thirdCommented:

ww,

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

 
0
 
thirdCommented:
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
 
mauliknaikAuthor Commented:
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
 
mouattsCommented:
Can you turn off 'show friendly error messages' and let us know what error you get.
0
 
webwomanCommented:
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
 
mauliknaikAuthor Commented:
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
 
webwomanCommented:
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
 
mauliknaikAuthor Commented:
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
 
lexxwernCommented:
<input type="button" value="download" onclick="javascript: window.location='zip.zip';"/>
0
 
mauliknaikAuthor Commented:

Thankx Lexxwern.
0
 
mauliknaikAuthor Commented:

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
 
lexxwernCommented:
so it worked?
0
 
lexxwernCommented:
IE6 i could refresh the original page.

NS6.2 i could.

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

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
 
lexxwernCommented:
what!!

what do u mean by throwing code?


do you want the page to refresh after a file has been downloaded?
0
 
lexxwernCommented:
<input type="button" value="download" onclick="javascript: window.open('proposal.doc'); window.location='test.html';"/>
0
 
mauliknaikAuthor Commented:

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
 
lexxwernCommented:
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
 
mouattsCommented:
I repeat Can you turn off 'show friendly error messages' and let us know what error you get.
0
 
mauliknaikAuthor Commented:

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
 
webwomanCommented:
Use a graphic of a button and make a regular link.
0
 
mauliknaikAuthor Commented:

Yaa, thats the last option with some compromise. But if possible then, i am looking for good option.
0
 
mouattsCommented:
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
 
mauliknaikAuthor Commented:
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
 
ahosangCommented:
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
 
moduloCommented:
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Hire Technology Freelancers with Gigs

Work with 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.

  • 18
  • 8
  • 7
  • +6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now