Skip to content

Commit 61dabcb

Browse files
committed
First
0 parents  commit 61dabcb

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

.project

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>crossDomain</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
</buildSpec>
9+
<natures>
10+
</natures>
11+
</projectDescription>

crossdomain.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function xdomain(par){//crossdomain function
2+
par.xpath=par.xpath==undefined?"*":par.xpath;
3+
par.type=par.type==undefined?"xml":par.type;
4+
xmlhttp=new XMLHttpRequest();
5+
par.url = 'http://query.yahooapis.com/v1/public/yql?q='+encodeURIComponent('select * from html WHERE url="'+par.url+'" AND xpath="'+par.xpath+'"')+'&format='+par.type+'&callback=cb';
6+
xmlhttp.open("GET",par.url,false);
7+
xmlhttp.onload=function(){
8+
function cb(d){return d;}//callBack bunction for returning results from query
9+
par.callBack(eval(xmlhttp.responseText));
10+
};
11+
xmlhttp.send();
12+
};
13+
xdomain({
14+
url:"http://cropdanka.com/",// url of site
15+
type:"xml",//return in xml or JSON format
16+
xpath:"*",//filter objects
17+
callBack:function(data){
18+
console.log(data);// display object returned from request
19+
var domElement=document.createElement("div");//create DOM
20+
domElement.innerHTML=data.results[0];// load result
21+
var options=domElement.querySelectorAll("option");//now we can make javascript selector
22+
for(var i in options)console.log(options[i].innerHTML);// and display results
23+
}
24+
});

index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<head>CrossDomain</head>
4+
</head>
5+
<body>
6+
<script src="crossdomain.js"></script>
7+
</body>
8+
</html>

0 commit comments

Comments
 (0)