IE 中的 Google 文档查看器

发布于 2024-08-31 13:45:39 字数 374 浏览 3 评论 0原文

我到处寻找解决方案,但找不到。我正在使用 Google 文档查看器 查看 PDF 文件。这是一个很棒的工具,但我似乎无法让它在 Internet Explorer(7 或 8)中运行。我的所有图像都显示为“丢失”图标。如果我从外部查看该文件,它似乎加载得很好并且它将开始工作(我假设是因为图像正在被缓存)。该文档正在 iframe 中显示,并且可以在所有其他浏览器中使用。有没有人遇到过让它在 IE 中工作的解决方案?如果没有,有没有可以显示PPT和PDF文件的替代方案?

I've searched high and low for a solution, but can't find one. I'm using Google Docs Viewer to view PDF files. It's a great tool, but I can't seem to get it working in Internet Explorer (7 or 8). All my images come up as a 'missing' icon. If I view the file externally, it seems to load fine and it will start working (I'm assuming because the images are being cached). The document is being displayed in an iframe and works in all other browsers. Has anyone come across a solution to get it to work in IE? If not, is there an alternative that can display PPT and PDF files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

内心荒芜 2024-09-07 13:45:39

我有同样的问题,但不认为要求用户将 URL 添加到 IE 中的受信任站点是可以接受的。

幸运的是,我发现了以下帖子

如果禁用第三方 cookie,嵌入版本的 Google 文档查看器 (gview) 将无法正确加载其图像。这个问题对于大多数 IE 用户来说都是一个问题,因为默认情况下它将被禁用。下面我提供了解决这个问题的方法,至少在 google 添加 p3p 之前。该问题的原始讨论可以在 Google 文档帮助论坛中找到。

我已经尝试过了,它可以在 IE8、IE7 和 IE6 中运行。

I have the same problem, but didn't think it was acceptable to have to ask users to add the URL to their trusted sites in IE.

Luckily I came across the following post:

The embedded version of Google Docs Viewer (gview) will not load its images correctly if third party cookies are disabled. This problem is an issue for most IE users as by default it will be disabled. Below I provide a work around to this problem for at least until google adds a p3p. The original discussion of the issue can be found at google docs help forum.

I've tried this out and it works in IE8, IE7 and IE6.

层林尽染 2024-09-07 13:45:39

我知道这是一个老问题,但由于问题仍然存在,并且我偶然发现了这个问题,答案指向一个空白网站,这里是 @codeinthehole 答案,以防万一其他人需要它。 (这次可以在 GitHub)

<?php
# This proxy code is a bypass for an existing flaw in Google Docs Viewer that breaks the functionality
# for some IE users. If you do not wish to use this code, select Google Standard Viewer rather than
# Enhanced Viewer in GDE Settings. Note that viewer toolbar customization options depend on this
# proxy workaround remaining enabled.
# 
# The problem this code addresses is discussed at length on Google's Help Forum:
# http://www.google.com/support/forum/p/Google+Docs/thread?tid=22d92671afd5b9b7&hl=en
# 
# This code is based on the work of Peter Chen. For more information, see:
# http://peterchenadded.herobo.com/gview/
#
# Peter's code is modified below to allow for cURL fallback, viewer toolbar customization,
# and to reflect changes in the viewer since the code was first released.
// test for allow_url_fopen in php config; try curl for function if disabled
if (ini_get('allow_url_fopen') !== "1") {
    if (function_exists('curl_version')) {
        $curl = 1;
    } else {
        $err = "This function is not supported on your web server. Please add ";
        $err .= "<code>allow_url_fopen = 1</code> to your php.ini or enable cURL library. ";
        $err .= "If you are unable to do this, please switch to Google Standard ";
        $err .= "Viewer in GDE Options.";
        echo $err;
        exit;
    }
}
if (isset($_GET['embedded'])) {
    // get the src page, change relative path to absolute
    if (isset($curl)) {
        $code = curl_get_contents("http://docs.google.com/viewer?" . $_SERVER['QUERY_STRING']);
    } else {
        $code = file_get_contents("http://docs.google.com/viewer?" . $_SERVER['QUERY_STRING']);
    }

    // fix path to images
    $search[] = "/viewer/images";
    $replace[] = "http://docs.google.com/viewer/images";
    $search[] = "/gview/images";
    $replace[] = "http://docs.google.com/viewer/images";

    // proxy the javascript file
    $search[] = "gview/resources_gview/client/js";
    $replace[] = "?jsfile=gview/resources_gview/client/js";
    if (isset($_GET['gdet'])) {
        $gdet = $_GET['gdet'];
        # hide google icon (i)
        /* These are no longer visible by default - not necessary
        if (strstr($gdet, 'i') !== false) { 
            $search[] = ".goog-logo-small {";
            $replace[] = ".goog-logo-small { display: none !important;";
        }
        # hide single/double page view (p)
        if (strstr($gdet, 'p') !== false) { 
            $search[] = ".controlbar-two-up-image {";
            $replace[] = ".controlbar-two-up-image { display: none !important;";
            $search[] = ".controlbar-one-up-image {";
            $replace[] = ".controlbar-one-up-image { display: none !important;";
        }
        */
        # hide zoom in/out (z)
        if (strstr($gdet, 'z') !== false) {
            $search[] = "#zoomOutToolbarButtonIcon {";
            $replace[] = "#zoomOutToolbarButtonIcon { display: none !important;";
            $search[] = "#zoomInToolbarButtonIcon {";
            $replace[] = "#zoomInToolbarButtonIcon { display: none !important;";
        }
        # hide open in new window (n)
        if (strstr($gdet, 'n') !== false) {
            $search[] = "#openInViewerButtonIcon {";
            $replace[] = "#openInViewerButtonIcon { display: none !important;";
        }
    }

    $code = str_replace($search, $replace, $code);

    header('Content-type: text/html');
    echo $code;

} else if (isset($_GET['a']) && $_GET['a'] == 'gt') {
    // get text coordinates file, can not redirect because of same origin policy
    if (isset($curl)) {
        $code = curl_get_contents("http://docs.google.com/viewer?" . $_SERVER['QUERY_STRING']);
    } else {
        $code = file_get_contents("http://docs.google.com/viewer?" . $_SERVER['QUERY_STRING']);
    }

    header('Content-type: text/xml; charset=UTF-8');
    echo $code;

} else if (isset($_GET['a']) && $_GET['a'] == 'bi') {
    // redirect to images  
    header("Location: http://docs.google.com/viewer?" . $_SERVER['QUERY_STRING']);
    header('Content-type: image/png');

} else if (isset($_GET['jsfile'])) {
    // proxy javascript files and replace navigator.cookieEnabled with false
    if (isset($curl)) {
        $code = curl_get_contents("http://docs.google.com/" . $_GET['jsfile']);
    } else {
        $code = file_get_contents("http://docs.google.com/" . $_GET['jsfile']);
    }

    $search = array("navigator.cookieEnabled");
    $replace = array("false");
    $code = str_replace($search, $replace, $code);

    header('Content-type: text/javascript');
    echo $code;

} else {
    // everything else, of which there isn't!  
    header("Location: http://docs.google.com/viewer?" . $_SERVER['QUERY_STRING']);
}
function curl_get_contents($url)
{
    $ch = curl_init();
    $timeout = 5; // set to zero for no timeout
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $file_contents = curl_exec($ch);
    curl_close($ch);

    return $file_contents;
}

I know this is a old question, but since the problem still persists and I've stumbled on this question with a answer pointing to a blank website, here is the actual code of the script mentioned at @codeinthehole answer, just in case someone else needs it. (It may be found, this time, at GitHub)

<?php
# This proxy code is a bypass for an existing flaw in Google Docs Viewer that breaks the functionality
# for some IE users. If you do not wish to use this code, select Google Standard Viewer rather than
# Enhanced Viewer in GDE Settings. Note that viewer toolbar customization options depend on this
# proxy workaround remaining enabled.
# 
# The problem this code addresses is discussed at length on Google's Help Forum:
# http://www.google.com/support/forum/p/Google+Docs/thread?tid=22d92671afd5b9b7&hl=en
# 
# This code is based on the work of Peter Chen. For more information, see:
# http://peterchenadded.herobo.com/gview/
#
# Peter's code is modified below to allow for cURL fallback, viewer toolbar customization,
# and to reflect changes in the viewer since the code was first released.
// test for allow_url_fopen in php config; try curl for function if disabled
if (ini_get('allow_url_fopen') !== "1") {
    if (function_exists('curl_version')) {
        $curl = 1;
    } else {
        $err = "This function is not supported on your web server. Please add ";
        $err .= "<code>allow_url_fopen = 1</code> to your php.ini or enable cURL library. ";
        $err .= "If you are unable to do this, please switch to Google Standard ";
        $err .= "Viewer in GDE Options.";
        echo $err;
        exit;
    }
}
if (isset($_GET['embedded'])) {
    // get the src page, change relative path to absolute
    if (isset($curl)) {
        $code = curl_get_contents("http://docs.google.com/viewer?" . $_SERVER['QUERY_STRING']);
    } else {
        $code = file_get_contents("http://docs.google.com/viewer?" . $_SERVER['QUERY_STRING']);
    }

    // fix path to images
    $search[] = "/viewer/images";
    $replace[] = "http://docs.google.com/viewer/images";
    $search[] = "/gview/images";
    $replace[] = "http://docs.google.com/viewer/images";

    // proxy the javascript file
    $search[] = "gview/resources_gview/client/js";
    $replace[] = "?jsfile=gview/resources_gview/client/js";
    if (isset($_GET['gdet'])) {
        $gdet = $_GET['gdet'];
        # hide google icon (i)
        /* These are no longer visible by default - not necessary
        if (strstr($gdet, 'i') !== false) { 
            $search[] = ".goog-logo-small {";
            $replace[] = ".goog-logo-small { display: none !important;";
        }
        # hide single/double page view (p)
        if (strstr($gdet, 'p') !== false) { 
            $search[] = ".controlbar-two-up-image {";
            $replace[] = ".controlbar-two-up-image { display: none !important;";
            $search[] = ".controlbar-one-up-image {";
            $replace[] = ".controlbar-one-up-image { display: none !important;";
        }
        */
        # hide zoom in/out (z)
        if (strstr($gdet, 'z') !== false) {
            $search[] = "#zoomOutToolbarButtonIcon {";
            $replace[] = "#zoomOutToolbarButtonIcon { display: none !important;";
            $search[] = "#zoomInToolbarButtonIcon {";
            $replace[] = "#zoomInToolbarButtonIcon { display: none !important;";
        }
        # hide open in new window (n)
        if (strstr($gdet, 'n') !== false) {
            $search[] = "#openInViewerButtonIcon {";
            $replace[] = "#openInViewerButtonIcon { display: none !important;";
        }
    }

    $code = str_replace($search, $replace, $code);

    header('Content-type: text/html');
    echo $code;

} else if (isset($_GET['a']) && $_GET['a'] == 'gt') {
    // get text coordinates file, can not redirect because of same origin policy
    if (isset($curl)) {
        $code = curl_get_contents("http://docs.google.com/viewer?" . $_SERVER['QUERY_STRING']);
    } else {
        $code = file_get_contents("http://docs.google.com/viewer?" . $_SERVER['QUERY_STRING']);
    }

    header('Content-type: text/xml; charset=UTF-8');
    echo $code;

} else if (isset($_GET['a']) && $_GET['a'] == 'bi') {
    // redirect to images  
    header("Location: http://docs.google.com/viewer?" . $_SERVER['QUERY_STRING']);
    header('Content-type: image/png');

} else if (isset($_GET['jsfile'])) {
    // proxy javascript files and replace navigator.cookieEnabled with false
    if (isset($curl)) {
        $code = curl_get_contents("http://docs.google.com/" . $_GET['jsfile']);
    } else {
        $code = file_get_contents("http://docs.google.com/" . $_GET['jsfile']);
    }

    $search = array("navigator.cookieEnabled");
    $replace = array("false");
    $code = str_replace($search, $replace, $code);

    header('Content-type: text/javascript');
    echo $code;

} else {
    // everything else, of which there isn't!  
    header("Location: http://docs.google.com/viewer?" . $_SERVER['QUERY_STRING']);
}
function curl_get_contents($url)
{
    $ch = curl_init();
    $timeout = 5; // set to zero for no timeout
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $file_contents = curl_exec($ch);
    curl_close($ch);

    return $file_contents;
}
孤独岁月 2024-09-07 13:45:39

我找到的解决此问题的唯一解决方案是将 https://docs.google.com 添加到您值得信赖的互联网站点。

The only solution I've found to this problem, is to add https://docs.google.com to your trusted internet sites.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文