javascript - 如何在javascript中使用href attrib scriptlet动态加载页面

标签 javascript google-apps-script location-href

您好,我正在尝试编写代码来动态打开网址,首先我尝试使用以下 HTML:

var rutaWeb = ScriptApp.getService().getUrl();
function doGet(e) {
 var page = e.parameter.p || "Web";
 return HtmlService.createTemplateFromFile(page).evaluate();
} 

<a href="<?!= rutaWeb + '?p=Alumno' ?>" Id="myA">Página Alumno</a>

并且工作正常,但我需要在单击按钮元素后执行该操作,因此我在脚本中对此进行了编码:

document.location.href = document.getElementById("myA").href;

但这给了我一个错误:

Refused to display 'https://script.google.com/macros/s/AKfycbwLXIef95aeUGyRFiP3lH_-Oac6ByXem17VjnPjdXpN/dev?p=indEntregas' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

这有什么问题,我该如何让它工作?

最佳答案

虽然我无法回答有关此问题的很多问题,但我找到了错误消息的解决方案...

为了查看打开的页面没有冲突,我将页面的目标选项设置为在“_blank”上打开,并按脚本中的方式设置 a 元素:

function abrirUrl(url) {
        var a = document.createElement("a");
        a.target = "_blank";
        a.href = url;
        a.click();

    }

    var url = "<?!= rutaWeb + '?p=Alumno' ?>";

然后单击按钮:

function abrirInicio(){
    abrirUrl(url);
}

关于javascript - 如何在javascript中使用href attrib scriptlet动态加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49261233/

相关文章:

javascript - 当 jQuery 过滤器不返回任何内容时显示消息

javascript - 处理JS中的查询字符串,如http_build_query等

javascript - jQuery:事件状态:将Class添加到包含document.href作为href的链接

javascript - 包含来自多个模块的 CSS (Sass)

javascript - Google Maps API V3 : multiple markers and ajax infowindows?(最佳性能)

javascript - 隐藏的 jQuery 可拖动包含溢出

javascript - 如何使用 Google 应用程序脚本通过 Google Business 应用程序获取组织内候选人的日历信息

google-apps-script - 在 Google Apps 脚本中将文件的所有权转移给其他用户

google-apps-script - Google Apps 脚本和 RFC 3339 问题