0

So, firstly I'd like to specific that I'm aware of the following code

window.open(url);

which has worked very well for me in the past.

The problem this time is that I'm trying to open a html file that isn't online as such. The file itself is here "http://coynesresources.weebly.com/uploads/7/6/5/3/76537449/small.html" and when I try to use the following

window.open("http://coynesresources.weebly.com/uploads/7/6/5/3/76537449/small.html");

only allows me to download the HTML file, rather than open it in my browser. Any help would be greatly appreciated.

Robbie Coyne
  • 11
  • 1
  • 3
  • 1
    What do you mean it "isn't online as such"? –  Jul 09 '16 at 15:33
  • @Amy I'm not sure how to explain it. The file is available on a server but it isn't a website. I'm not entirely sure tbh, I just know that the link is only serving as a download link for some reason. – Robbie Coyne Jul 09 '16 at 15:36
  • 1
    If its reachable across the Internet, then it's online by definition. –  Jul 09 '16 at 15:37
  • @Amy Fair enough, but that doesn't solve my problem by any means. – Robbie Coyne Jul 09 '16 at 15:39
  • This is the way the server is providing the file. An option would be to consume it and render it into a container element. – Anthony Sherratt Jul 09 '16 at 15:46
  • @AnthonySherratt Thanks, could you show me how to do that in html/javascript? I'm not experienced with this stuff at all. – Robbie Coyne Jul 09 '16 at 15:47

3 Answers3

0

You can't use direct ajax query for this url (crossdomain policy). So you must use proxy with jsonp. See: Loading cross domain endpoint with jQuery AJAX

And working example for you: http://jsbin.com/bahigodiru/1/edit?html,js,output


But it is not good solution. There are a lot of free hostings that you can use. Or use jsfiddle/jsbin (for jsbin you can get link to page without online editor: http://jsbin.com/bahigodiru/1/ )


weebly.com is a platform to create a site. You should not upload you html as file. You should add it's content as custom html: https://www.weebly.com/blog/file-upload-new-linker-custom-html-and-a-new-upgrade-process

Community
  • 1
  • 1
Tarwirdur Turon
  • 751
  • 5
  • 17
  • This is probably the answer the OP is looking for, but if jQuery is not an option, a pure JS approach is possible as shown here: http://stackoverflow.com/a/6132828/1990536 ...However, I would encourage jQuery. – Rai Jul 09 '16 at 17:00
0

Try this

window.open("http://coynesresources.weebly.com/uploads/7/6/5/3/76537449/small.html", "windowName", "width=200,height=100",false);

more information see here

http://www.w3schools.com/jsref/met_win_open.asp

https://developer.mozilla.org/en-US/docs/Web/API/Window/open

A.K.
  • 2,284
  • 3
  • 26
  • 35
0

I'm going to guess that you can't.

The issue is the server is returning a header that tells the browser to download it instead of display it

curl -v "http://coynesresources.weebly.com/uploads/7/6/5/3/76537449/small.html"
*   Trying 199.34.228.54...
* Connected to coynesresources.weebly.com (199.34.228.54) port 80 (#0)
> GET /uploads/7/6/5/3/76537449/small.html HTTP/1.1
> Host: coynesresources.weebly.com
> User-Agent: curl/7.43.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx
< Date: Sat, 09 Jul 2016 19:17:29 GMT
< Content-Type: text/html
< Content-Length: 904
< Last-Modified: Sat, 09 Jul 2016 15:10:54 GMT
< Connection: keep-alive
< ETag: "578113fe-388"
< Expires: Sat, 16 Jul 2016 19:17:29 GMT
< Cache-Control: max-age=604800
< Content-Disposition: attachment
< Accept-Ranges: bytes
< X-W-DC: SFO
< 

That Content-Disposition: attachment part tells the browser to download instead of display

See RFC 6266

4.2. Disposition Type

If the disposition type matches "attachment" (case-insensitively), this indicates that the recipient should prompt the user to save the response locally, rather than process it normally (as per its media type).

Community
  • 1
  • 1
gman
  • 100,619
  • 31
  • 269
  • 393