1

I have an application which is written entirely as html/js (there is no server). Using javascript, I would like to retrieve a script from another domain and get its contents as a string. I do not want to evaluate the script. Is there any hack which can make this possible?

1
  • Thanks all. I was hoping for a way to do it without any server support, but it sounds like that just isn't possible. Commented Oct 25, 2009 at 16:48

4 Answers 4

3

I do not think so. If there were a way, it would violate the ban of cross domain downloads. I guess there is a way to relax these limitations by properly configuring the security on the browser, but it is messy and unreliable among other things because of browser dependencies. You will have to do it on the server

Sign up to request clarification or add additional context in comments.

Comments

2

Sounds like JSONP for me.

1 Comment

Yep, although that sounds like evalling :)
1

You can't. The cross-domain security model implemented by browsers prevents this. You'd need to go through another a server on your domain as a proxy which can access the remote resource for you.

Comments

1

It's definitely possible. Instead of using jQuery or other libraries that implements the JSONP technique, implement JSONP yourself!

There's a few steps, but at the end, skip the "eval" part. Instead do what you want to do with the javascript string...

A nice in depth article is hard to find but here's one I quickly found:

http://niryariv.wordpress.com/2009/05/05/jsonp-quickly/

JSONP is in fact, a pretty clever technique. Learning it just for the fun of it is worthwhile!

Good luck

1 Comment

I forgot, the script on the other domain should also be JSONP friendly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.