如何让onchange设置onclick=window.open(url)?
How to get onchange to set onclick=window.open(url)?
我在 GAS html 服务中有一个应用程序,它有一个文件选择框,旁边有一个按钮,用于在新选项卡中打开它们。我不知道如何完成它。列表中的文件以 google-drive-file-id 形式获取它们的值(假设 fileID1-3 没问题),我有一个服务器脚本来获取整个 link。操作方法如下:
HTML:
<select id='fileBox' name='fileBox' onchange="google.script.run.withSuccessHandler(gotFileLink).getFileLinkById(this.value)">
<option value=fileID1>File1.pdf</option>
<option value=fileID2>File2.pdf</option>
<option value=fileID2>File3.pdf</option>
</select>
<input type="button" value="Open File" id="linkButton" />
服务器代码:
function getFileLinkById(fileID) { return DriveApp.getFileById(fileID).getUrl(); }
客户代码:
function gotFileLink(url) {
document.getElementById('linkButton').onclick = // what goes here?
}
我已经使用 "window.open" 尝试了几种选择,但无法弄清楚如何让它发挥作用。
提前致谢。
这是可以帮助您在单击按钮时打开所需 link 的代码。
这是一个有效的 link:
JSFIDDLE
<select id='fileBox' name='fileBox'>
<option value='http://www.google.com'>File1.pdf</option>
<option value='http://www.google.com'>File2.pdf</option>
<option value='http://www.google.com'>File3.pdf</option>
</select>
<input type="button" value="Open File" id="linkButton" />
var btn = document.getElementById('linkButton');
btn.addEventListener('click',GetInfo,false);
function GetInfo(){
var e = document.getElementById("fileBox");
var selectedUrl = e.options[e.selectedIndex].value;
window.open(selectedUrl);
}
回答我自己的问题,但基于 maxspan 的解决方案(这不是我想要的)我能够以另一种方式解决这个问题:
<select id='fileBox'>
<option value=fileID1>File1.pdf</option>
<option value=fileID2>File2.pdf</option>
<option value=fileID2>File3.pdf</option>
</select>
<input type="button" value="Open File" id="linkButton" onclick="runner.withSuccessHandler(window.open).getFileLinkById(document.getElementById('fileBox').value)" />
如果有人有 different/better 答案 - 我仍然想听...感谢 maxspan 帮助我。
我在 GAS html 服务中有一个应用程序,它有一个文件选择框,旁边有一个按钮,用于在新选项卡中打开它们。我不知道如何完成它。列表中的文件以 google-drive-file-id 形式获取它们的值(假设 fileID1-3 没问题),我有一个服务器脚本来获取整个 link。操作方法如下:
HTML:
<select id='fileBox' name='fileBox' onchange="google.script.run.withSuccessHandler(gotFileLink).getFileLinkById(this.value)">
<option value=fileID1>File1.pdf</option>
<option value=fileID2>File2.pdf</option>
<option value=fileID2>File3.pdf</option>
</select>
<input type="button" value="Open File" id="linkButton" />
服务器代码:
function getFileLinkById(fileID) { return DriveApp.getFileById(fileID).getUrl(); }
客户代码:
function gotFileLink(url) {
document.getElementById('linkButton').onclick = // what goes here?
}
我已经使用 "window.open" 尝试了几种选择,但无法弄清楚如何让它发挥作用。 提前致谢。
这是可以帮助您在单击按钮时打开所需 link 的代码。
这是一个有效的 link: JSFIDDLE
<select id='fileBox' name='fileBox'>
<option value='http://www.google.com'>File1.pdf</option>
<option value='http://www.google.com'>File2.pdf</option>
<option value='http://www.google.com'>File3.pdf</option>
</select>
<input type="button" value="Open File" id="linkButton" />
var btn = document.getElementById('linkButton');
btn.addEventListener('click',GetInfo,false);
function GetInfo(){
var e = document.getElementById("fileBox");
var selectedUrl = e.options[e.selectedIndex].value;
window.open(selectedUrl);
}
回答我自己的问题,但基于 maxspan 的解决方案(这不是我想要的)我能够以另一种方式解决这个问题:
<select id='fileBox'>
<option value=fileID1>File1.pdf</option>
<option value=fileID2>File2.pdf</option>
<option value=fileID2>File3.pdf</option>
</select>
<input type="button" value="Open File" id="linkButton" onclick="runner.withSuccessHandler(window.open).getFileLinkById(document.getElementById('fileBox').value)" />
如果有人有 different/better 答案 - 我仍然想听...感谢 maxspan 帮助我。