简体   繁体   English

访问Google网站上的页面以加载到我的网站上

[英]Accessing pages on Google Sites to load on my site

Via javascript (jQuery) I'm trying to load the contents of some pages from Google Sites onto elements in pages in a different site. 我正在尝试通过JavaScript(jQuery)将Google站点中某些页面的内容加载到其他站点中页面的元素中。 Using jQuery's load I get the expectable: 使用jQuery的负载,我得到了预期的效果:

XMLHttpRequest cannot load https://sites.google.com/site/foo/home. No 'Access-Control-
Allow-Origin' header is present on the requested resource. Origin 'http://bar' is 
therefore not allowed access.

I tried with CORS, using the code below (which I found at http://www.html5rocks.com/en/tutorials/cors/ ), but got the same result. 我使用下面的代码(在http://www.html5rocks.com/en/tutorials/cors/上找到)尝试了CORS,但是得到了相同的结果。

function createCORSRequest(method, url) {
  var xhr = new XMLHttpRequest();
  if ("withCredentials" in xhr) {
    // XHR for Chrome/Firefox/Opera/Safari.
    xhr.open(method, url, true);
  } else if (typeof XDomainRequest != "undefined") {
    // XDomainRequest for IE.
    xhr = new XDomainRequest();
    xhr.open(method, url);
  } else {
    // CORS not supported.
    xhr = null;
  }
  return xhr;
}

function makeCorsRequest() {
  var url = 'https://sites.google.com/site/edumonkihelp/test0';

  var xhr = createCORSRequest('GET', url);
  if (!xhr) {
    alert('CORS not supported');
    return;
  }

  xhr.onload = function() {return xhr.responseText;};
  xhr.onerror = function() {alert('Woops, there was an error making the request.');};
  xhr.send();
}

So I guess I have two questions: 1. Can you access the contents of pages in Google Sites? 因此,我想我有两个问题:1.您可以访问Google协作平台中页面的内容吗? 2. Are there any other similar services out there that would allow you to do so? 2.还有其他类似的服务可让您这样做吗?

Thanks! 谢谢!

According to Google Sites Data API you can use the path parameter to fetch that particular page located at http://sites.google.com/site/siteName/path/to/the/page : 根据Google Sites Data API,您可以使用path参数来获取位于http://sites.google.com/site/siteName/path/to/the/page特定页面:

GET /feeds/content/domainName/siteName?path=/path/to/the/page

In order to perform Ccoss-domain requests using jQuery.ajax() specify dataType: 'jsonp' 为了使用jQuery.ajax()执行Ccoss域请求,请指定dataType: 'jsonp'

Example

The example demonstrates how to retrieve page located at https://sites.google.com/site/nokiaofficescontacts/hq : 该示例演示了如何检索位于https://sites.google.com/site/nokiaofficescontacts/hq页面:

$.ajax({
    url: 'https://sites.google.com/feeds/content/site/nokiaofficescontacts?path=/hq&alt=json',
    success: function (data) { 
        console.log('Page was succesfully retrieved');
        console.log(data.feed.entry[0].title); //print Page Title
    },
    error: function (error) {
        console.log(JSON.stringify(error));
    },
    dataType: 'jsonp'
});

Note: alt=json is specified to request a response in JSON format. 注意:指定alt=json以请求JSON格式的响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 阻止外部站点访问我的ashx页面 - Prevent external sites from accessing my ashx pages 如何在嵌入到相同网站页面的新Google-Site [2018]中添加嵌入式按钮? - How to add embedded buttons to new Google-Sites [2018], linked to the same site pages? 如何在我的网站上加载谷歌地图? - how to load google map in My site? 阻止Google通过我网站上的链接创建页面 - Prevent Google from creating pages from links on my site 如何创建一个 javascript 小部件来从我的 wordpress 站点加载最近的帖子并在其他站点中显示? - How to create a javascript widget to load recent posts from my wordpress site and display in other sites? DoubleTapToGo-无法在此站点上运行,可在我的其他站点上运行 - DoubleTapToGo - Not Working On This Site, Works On My Other Sites 如何使用API​​在我的网站内加载Google图片? - How to load google images within my site using api? 无法在Google网站中加载外部网址 - Failed to load external url in Google sites ..未正确加载Google Maps ...如何处理旧网站/新页面的开发 - ..didn't load Google Maps correctly… how to handle development of old site/new pages 在谷歌网站上创建的网站上的Google Maps Javascript API - Google Maps Javascript API on a site created on google sites
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM