views:

91

answers:

4

What is needed is as follows:

I have an HTML webpage and I need to access another website and get something from its source code.

I want to run something like

link = "http://www.google.com";
doc.querySelectorAll('#courses_menu > ul > li > a'); // Apply on the link.

to get what I need from the link and use it!

However, I am using Jetpack slide bar.

Does it have to do anything with HTTP requests?

A: 

Have a page which will have a result of your query "doc.querySelectorAll('#courses_menu > ul > li > a');"

Add an IFrame in your page, set the src as the page which has the above result.

<iframe src='pagenamewhichhasresult'/>

Ramesh
have you tried this? I don't think this would work due to the same origin policy.
darren
A: 

You can include other website content in your html document using an iframe. However, due to the same original policy, you cannot have script from your domain affect content from another domain. In other words, you can't write some javascript to manipulate the content of some other web page you put in an iframe. The script would have to come from that domain as well.

darren
+2  A: 

I think you could pull the entire page using an Ajax request, put the content in a hidden iframe, and then manipulate the DOM in the iframe. Something like (here using the jQuery framework)

<iframe id="holder" style="display: none">

<script type="text/javascript">
$("#holder").load("http://www.google.com",function () {
  $link = $("#holder").contents().find("#courses_menu > ul > li > a");
});
</script>
Jordan Reiter
A: 

I recommend using a Ajax (e.g. jquery) with a PHP proxy on the same Webserver. The Proxy loads the the remote webpage and is then available under the same domain.

Don't forget to protect the proxy against abuse.

Synox