自定义Google文档查看器的CSS [英] Customize CSS of Google Docs Viewer

查看:97
本文介绍了自定义Google文档查看器的CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何自定义Google文档视图iframe的CSS?

How do i customize the CSS of the google docs view iframe?

我意识到iframe正在从跨域源获取我无法控制的内容,我只是想知道是否有人对此有一些黑客?

I realize that the iframe is getting the content from a cross domain source which i do not control, i was just wondering if anyone has some sort of hack around this?

推荐答案

我问这个,它的完全黑客和基于另一个线程的答案SO

I asked this so i could post the solution. Its totally hacky and based off of a an answer from another thread on SO.

我不得不进行一些修改,使其工作,因为上面的链接上面的答案不适用于google docs。

I had to make a few modifications to get it working because the answer linked above didn't quite work with google docs.

基本上你代理请求服务器端,修改html然后中继iframe内容。

Basically you proxy the requests server side, modify the html and then relay the iframe contents.

<?php
if ( isset( $_GET['a'] ) && $_GET['a'] == 'gt') {
    // proxy xml content - must be done to avoid XSS failures (contains embedded link data and enables text selection)
    $code = gde_get_contents("https://docs.google.com/viewer?" . $_SERVER['QUERY_STRING']);
    header('Content-type: application/xml');
    echo $code;
} elseif ( isset( $_GET['a'] ) && $_GET['a'] == 'bi' ) {
    // proxy image content - prevents "too many redirects" on many-paged docs
    header( "Location: https://docs.google.com/viewer?" . $_SERVER['QUERY_STRING'] );
} elseif ( isset( $_GET['jsfile'] ) ) {
    // proxy javascript content - not doing anything here but Google changes return 404 if not proxied (??)
    $code = file_get_contents("https://docs.google.com/" . $_GET['jsfile']);  
    header('Content-type: text/javascript');  
    echo $code; 
} else {
  $content = file_get_contents('http://docs.google.com/viewer?url=http%3A%2F%2Fwww.someurlhere.com%2Fgoogledocs%2Ftest.docx&embedded=true');
  $content = str_replace('gview/resources_gview/client/js','/googledocs/index.php?jsfile=gview/resources_gview/client/js', $content);
  $content = str_replace('</head>','<link rel="stylesheet" href="http://www.example.com/google.css" /></head>', $content);
  header('Content-type: text/html; charset=utf-8');
  echo $content;  
}
?>

确保更改行:

file_get_contents('http://docs.google.com/viewer?url=http%3A%2F%2Fwww.someurlhere.com%2Fgoogledocs%2Ftest.docx&embedded=true');

到您尝试托管的iframe的适用网址。

to the applicable url for the iframe you are trying to host.

同时更改行:

  $content = str_replace('</head>','<link rel="stylesheet" href="http://www.example.com/google.css" /></head>', $content);

要链接到您的样式表。

这篇关于自定义Google文档查看器的CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆