0

So basically we are trying to read a text or html file from external server which we don't have control off .

We are using script src tag to fetch the file but we are unable to read it

<script type="text/css" id="Script1" src="http://www.thirdparty.com/example.txt" ></script>

like in this screenshot you can see we are fetching a random txt file and we are getting a response but through javascript we are unable to read it .

Screenshot Image link

So now our motive is to read the example.txt file and store the content into a javascript variables.

Things that we have already tired but didn't work due to some or other reason

  1. Using XHR and jQuery load function

    $(document).ready(function () { $("#container").load("http://www.thirdparty.com/example.txt"); });

    but as I said its third party server and we don't have control over it , that's due to Cross-Origin XMLHttpRequest we are not getting any response from the server. by the way is there anyways to eliminate origin header from the xhr request ?

  2. Using proxy server wont work because of ip issue and cookies needs to be send from the client side.

  3. Getting innerhtml and innertext of the script tag but it didn't return the response rather it give code between tag which is not required .

P.S. we what something client side javascript bases solution not serverside due to some specific requirements .

thanks in advance for helping

OzrenTkalcecKrznaric
  • 5,535
  • 4
  • 34
  • 57
priya poojari
  • 11
  • 1
  • 3
  • this sounds dodgy. Why would you want to load a file into a browser using javascript? That file could contain anything. Any browser would block it. – Liam Jun 15 '13 at 14:38
  • If you have admin access to the external server, you can set up CORS and ajax it over, rather than using a _HTML_ element. From there, you can then read in _JavaScript_ and or apply to _HTML_. – Paul S. Jun 15 '13 at 14:39
  • @PaulS. As i have sepecified in my post NO I dont have access to the server so cant do that . – priya poojari Jun 15 '13 at 19:26
  • You could fetch from your server via _PHP_, then pass to client from your server (at the cost of more bandwidth and loss of client-third party authentication). – Paul S. Jun 15 '13 at 23:17

1 Answers1

2

It's not possible due to security reasons. There is no, I repeat NO way to do this on modern browsers. At least with JS. You could use JAVA, but it's probably not what You want.

Flash Thunder
  • 11,672
  • 8
  • 47
  • 91
  • Oh thats depressing ! yeah i want site A (my site) to load resource from site B (external site which i dont have control off) and read it, process it on client side using javascript or maybe plugins like FLASH or any simple trick or hack which can make it possible on most of mainstream modern browsers. Thanks – priya poojari Jun 15 '13 at 19:31
  • Sorry, not a chance. – Flash Thunder Apr 18 '17 at 17:29