You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Customcert插件的证书按钮在新页面打开?

修改Customcert插件按钮为新窗口打开的方法

针对你找到的view.php代码片段,只需在创建single_button实例后添加一行代码,即可实现按钮在新窗口打开:

// Create the button to download the customcert.
$downloadbutton = '';
if ($canreceive) {
    $linkname = get_string('getcustomcert', 'customcert');
    $link = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id, 'downloadown' => true));
    $downloadbutton = new single_button($link, $linkname, 'get', true);
    // 新增该行,设置按钮在新窗口打开
    $downloadbutton->attributes['target'] = '_blank';
    $downloadbutton->class .= ' m-b-1';  // Seems a bit hackish, ahem.
    $downloadbutton = $OUTPUT->render($downloadbutton);
}

原理说明

Moodle的single_button类支持通过attributes数组自定义HTML属性,添加target="_blank"后,渲染生成的按钮链接会自动带上该属性,点击时将在新窗口打开目标页面。

如果上述方法因Moodle版本差异不生效,可尝试备选方案(直接修改渲染后的HTML):

// 渲染按钮后添加替换逻辑
$downloadbutton = $OUTPUT->render($downloadbutton);
$downloadbutton = str_replace('<a ', '<a target="_blank" ', $downloadbutton);

内容的提问来源于stack exchange,提问作者Patricio López

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 11:40:38