例如,个人网站通常都会嵌入一段google analytics的js代码
既然javascript不允许跨域访问,那这段js代码是怎么把用户访问或点击的信息传给google服务器的?
------解决方案--------------------
script动态加载google的页面,参数附加客户的动作
js无法直接操作跨域的iframe内容,ajax不能直接请求跨域页面,看你js要进行什么操作了,不是说所有跨域操作都不允许
------解决方案--------------------
有的允许了。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>
xxx
</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script type="text/javascript">
jQuery(document).ready(function() {
$.ajax({
type: "get",
async: false,
data: {
},
url: "http://www.geonames.org/postalCodeLookupJSON?postalcode=10504&country=US",
dataType: "jsonp",
jsonp: "callback",
success: function(json) {
for (var e in json.postalcodes[0]) {
document.write(e + "--->" + json.postalcodes[0][e]+"<br/>");
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
});
});