简体   繁体   中英

What are these Google-calendar events from?

It seems it's fairly common practice to grab the contents of a Google-calendar embed code, and add a stylesheet into it (either manually or through something like a PHP script ) and display a custom-styled public calendar.

The odd thing is, I noticed if you click the print button at the top, or the "Google Calendar" in the lower right, it goes to localhost or whatever domain the page is - not the Google calendar.

If you try to trace the " gcal$func$[3](); " onclick through the Chrome devtools, or through Firefox with gcal$func$[3].toSource(); it will not find it or say

"function () {
    [native code]
}"

So where is this function coming from, and how can you tweak this to make it open in a new window with the Google url, not the current domain (404)?

According to the Google Calendar embed JS code, the function points to the following code

window.open(Pf(this.ciNb + "/render", "cid", b))

this.ciNb represents the base URL, which is by default the domain where the script runs (in your case that's your domain). However, it's intended to be google.com domain and fortunately, it's very easy to change that. baseURL is one of the parameters in the initialization script (declared in the page you're grabbing) and you just need to configure that to https://www.google.com .

If you use PHP, your code might look like this.

$page = new DOMDocument("1.0", "utf-8");
// grab the Google Calendar code
$page->loadHTMLfile("https://www.google.com/calendar/embed?src=yourcalendar%40gmail.com");
// set up the baseUrl and print the grabbed page
echo str_replace('"baseUrl":"/"', '"baseUrl":"https://www.google.com/"', $page->saveHTML());

Now all the links should work correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM