Google Docs viewer returning 204 responses, no longer working, alternatives?

后端 未结 7 1929
执念已碎
执念已碎 2020-12-08 01:01

UPDATE 2016-11-16 9:53am EST

It appears many people are still seeing 204 responses even though Google has claimed to have \"fixed\" the problem. Wh

7条回答
  •  醉酒成梦
    2020-12-08 01:52

    A simple solution/hack with Reactjs, though can be easily implemented to any other library/vanilla.

    Used with a basic concept : tries to load - if onload accomplish, clear interval, otherwise try to load again every 3 sec. works perfectly

    (I've edited my own code it so it will contain minimum code, so not tested)

    var React = require('react');

    export default class IframeGoogleDocs extends React.Component {
        constructor(props) {
            super();
            this.bindActions();
        }
        bindActions() {
            this.updateIframeSrc = this.updateIframeSrc.bind(this);
            this.iframeLoaded = this.iframeLoaded.bind(this);
        }
        iframeLoaded() {
            clearInterval(this.iframeTimeoutId);
        }
        getIframeLink() {
            return `https://docs.google.com/gview?url=${this.props.url}`; // no need for this if thats not dynamic
        }
        updateIframeSrc() {
            this.refs.iframe.src = this.getIframeLink();
        }
        componentDidMount() {
            this.iframeTimeoutId = setInterval(
                this.updateIframeSrc, 1000 * 3
            );
        }
        render() {
            return (
                
            );
        }
    }
    

提交回复
热议问题