我在 Google 日历 中遇到了这个问题。我想在较暗的背景上设置样式并更改字体。
幸运的是,嵌入代码中的 URL 对直接访问没有限制,因此通过使用 PHP 函数 file_get_contents 可以获得
页面的全部内容。可以调用位于您服务器上的 php 文件,而不是调用 Google URL,例如。 google.php,将包含修改后的原始内容:
$content = file_get_contents('https://www.google.com/calendar/embed?src=%23contacts%40group.v.calendar.google.com&ctz=America/Montreal');
将路径添加到样式表:
$content = str_replace('</head>','<link rel="stylesheet" href="http://www.yourwebsiteurl.com/google.css" /></head>', $content);
(这会将您的样式表放在最后一个 head 结束标记之前。)
在css和js相对调用的情况下,指定原始url的base url:
$content = str_replace('</title>','</title><base href="https://www.google.com/calendar/" />', $content);
最终的google.php 文件应如下所示:
<?php
$content = file_get_contents('https://www.google.com/calendar/embed?src=%23contacts%40group.v.calendar.google.com&ctz=America/Montreal');
$content = str_replace('</title>','</title><base href="https://www.google.com/calendar/" />', $content);
$content = str_replace('</head>','<link rel="stylesheet" href="http://www.yourwebsiteurl.com/google.css" /></head>', $content);
echo $content;
然后将iframe嵌入代码更改为:
<iframe src="http://www.yourwebsiteurl.com/google.php" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
祝你好运!