如何在<head>中添加<noscript>标记?


8

如果要在head标签中添加JavaScript,请使用drupal_add_js($js, 'inline')。这将添加一个<script type="text/javascript">

如何添加<noscript>标签?我也想添加以下内容<head>

<noscript>
  <meta http-equiv="refresh" content="5;url=<?php echo $file ?>" />
</noscript>

顺便说一句,我为此使用了一个简单的模块。

function custom_download_menu() {
    $items['download-code'] = array(
    'title callback' => 'custom_download_page_title',
    'page callback' => 'custom_download_view',
    'access arguments' => array('access content'),
    'access callback' => TRUE,
    );
    return $items;
  }

function custom_download_view() {
    $js = "var time_left = 5;
        var cinterval;

        function time_dec(){
            if(time_left > 0) time_left--;
            document.getElementById('countdown').innerHTML = 'Your download will start in ' + time_left + ' seconds...';
            if(time_left < 1){
                clearInterval(cinterval);
                window.location = '<?php echo $file ?>';
            }
        }

        cinterval = setInterval('time_dec()', 1000);";

    drupal_add_js($js, 'inline');
}

Answers:


10

您可以使用将元素添加到<head>网页的该部分drupal_add_html_head()

$target = url('enable-javascript', array('absolute' => TRUE));
$meta = array(
  '#theme' => 'html_tag',
  '#tag' => 'meta',
  '#attributes' => array(
    'http-equiv' => 'refresh',
    'content' => "2; url=$target"
  )
);
$noscript = array(
  '#theme' => 'html_tag',
  '#tag' => 'noscript',
  '#value' => drupal_render($meta)
);
drupal_add_html_head($noscript, 'noscript');

API文档


2
如果需要添加原始标记,则可以使用#type =>标记和#markup => your_raw_markup。参见api.drupal.org/comment/11274#comment-11274
2014年

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.