嘗試明確渲染:代碼從google javascript api
<!DOCTYPE html>
<html>
<head>
<title>Save to Drive Demo: Explicit Render</title>
<link rel="canonical" href="http://www.example.com">
<script src="https://apis.google.com/js/platform.js">
{parsetags: 'explicit'}
</script>
</head>
<body>
<a href="javascript:void(0)" id="render-link">Render the Save to Drive button</a>
<div id="savetodrive-div"></div>
<script>
function renderSaveToDrive() {
gapi.savetodrive.render('savetodrive-div', {
src: '//example.com/path/to/myfile.pdf',
filename: 'My Statement.pdf',
sitename: 'My Company Name'
});
}
document.getElementById('render-link').addEventListener('click', renderSaveToDrive);
</script>
</body>
</html>
數據-src網址可以從另一個域服務,但來自HTTP服務器的響應需要支持HTTP OPTION請求,包括以下幾個特殊的HTTP標頭:
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Range
Access-Control-Expose-Headers: Cache-Control, Content-Encoding, Content-Range
看到https://developers.google.com/drive/web/savetodrive#cors –
否則有什麼不對的文件路徑 - 這也將導致此錯誤 –
它仍然沒有按」 t工作地址= http://samrobbins.125mb.com/googledrive.html – samrobbins