一个Google gadget是嵌入在小工具容器中的 iframe,如 Google Sites 。 示例:https://sites.google.com/site/michaelmccolin/test
但是,由于 Google 小工具和 Google 协作平台位于两个不同的域中,您无法使用 window.parent.location
获取小工具父 URL。好消息是父 URL 作为参数值包含在小工具 (iframe) URL 中。示例:
https://slr19h92al8so047kuchhg5aog1sb42l-a-sites-opensocial.googleusercontent.com/gadgets/ifr?url=http://hosting.gmodules.com/ig/gadgets/file/116132513635841516857/sample.xml&container=enterprise&view=default&lang=en&country=ALL&sanitize=0&v=3bad4b3f87c8b199&libs=core&mid=167&parent=https://sites.google.com/site/michaelmccolin/test#st=e%3DAIHE3cDvCGmbZDEAvjS%252BWTpqst9FseOLNB%252BMd8IoyLxY3kypcxAriuGzs%252FtCova0JAhrFqKK2kKB3qFgru2PBUTYWMIIcmPaw4iAl7DIaUqyPKO56DpM9mcbQqh1bIa23t89yrL7maxL%26c%3Denterprise&rpctoken=9057528913578437337
问题是如何从小工具 URL 获取 parent
参数值。
谢谢!
最佳答案
您可以按如下方式访问查询字符串:
var queryString = location.search.substr( 1 );
从这里开始,更容易在分隔符处分割它并从中创建一个对象:
var queryObject = {};
queryString.split( '&' ).forEach( function objectFromPair( pairString ){
var pairArray = pairString.split( '=' );
queryObject[ pairArray[ 0 ] ] = pairArray[ 1 ];
} );
接下来,检索父
key :
var parentUrl = queryObject.parent;
关于javascript - 如何获取 Google 小工具 URL 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20970144/