使用主要网址参数替换iframe Google工作表ID

时间:2019-11-07 22:34:53

标签: javascript google-sheets-api

我不确定是否可行...我正在尝试用作为大型机URL参数一部分的字符串替换iframe中URL的特定部分。

即我正在尝试动态替换iframe Google表格的公共URL ID,以呈现与mainframes参数关联的表格。

大型机网址:www.mysite.com?sfds654fsgfg6sfg54gfhghdf6

iframe src =“” https://docs.google.com/spreadsheets/d/e/[google id可以从大型机动态插入到此处] / pubhtml吗?

预期的最终结果

iframe src =“” https://docs.google.com/spreadsheets/d/e/sfds654fsgfg6sfg54gfhghdf6/pubhtml

javascript也是我的限制

谢谢

1 个答案:

答案 0 :(得分:-1)

我将you have the id you want to use假定为变量,并且您在页面中还有一个要放置此iFrame的地方。

var url_string = window.location.href;
var url = new URL(url_string);
var id= url.searchParams.get("id"); //Or whatever your url parameter is called.
var iFrameDestination = document.getElementbyId("#iframeDest");

var ifrm = document.createElement('iframe');
ifrm.setAttribute('src', 'https://docs.google.com/spreadsheets/d/e/'+id+'/pubhtml');
iFrameDestination.appendChild(ifrm);