user220755
user220755

Reputation: 4446

Get the source code of a URL using JavaScript

I am trying to get the source code of a page (let's say google.com) using Javascript. The code I tried is below but the issue remains the same which is that I am accessing a different domain. What I am trying to do is to check the source code of a page, check for a specific value in that source code and behave based on that information. Thanks!

$.get(url, function(data){ something(data); }//end function(data) );//end get

Upvotes: 0

Views: 227

Answers (1)

Denys Séguret
Denys Séguret

Reputation: 382150

You can't do it if the page is from another domain and doesn't specifically allow it with CORS headers. See the Same Origin Policy.

The only "workaround" is using a server, either fetching the source for you or acting as proxy.

Upvotes: 2

Related Questions