javascript를 </body></html>태그전에 위치시킬 필요가 있을 경우
그누보드의 add_javascript()를 수정하지 않고 add_tail_javascript()를 추가해서 </body>태그전에 javascript를 위치하게 하는 방법입니다.
/lib/common.lib.php
1. add_javascript()다음에 아래 코드 삽입
[code]
function add_tail_javascript($javascript, $order=0)
{
global $html_process;
if(trim($javascript) && method_exists($html_process, 'merge_tail_javascript') )
$html_process->merge_tail_javascript($javascript, $order);
}
[/code]
2. merge_javascript()다음에 아래 코드 삽입
[code]
function merge_tail_javascript($javascript, $order)
{
$tail_scripts = $this->tail_js;
$is_merge = true;
foreach($tail_scripts as $script) {
if($script[1] == $javascript) {
$is_merge = false;
break;
}
}
if($is_merge)
$this->tail_js[] = array($order, $javascript);
}
[/code]
3. run()... 부분
if(!empty($scripts)) {
...
}
하단에 아래코드 삽입
[code]
$tail_javascript = '';
$tail_scripts = $this->tail_js;
$php_eol = '';
unset($order);
unset($index);
if(!empty($tail_scripts)) {
foreach ($tail_scripts as $key => $row) {
$order[$key] = $row[0];
$index[$key] = $key;
$script[$key] = $row[1];
}
array_multisort($order, SORT_ASC, $index, SORT_ASC, $tail_scripts);
$tail_scripts = run_replace('html_process_script_files', $tail_scripts);
foreach($tail_scripts as $js) {
if(!trim($js[1]))
continue;
$js[1] = preg_replace('#\.js([\'\"]?>)<\/script>$#i', '.js?ver='.G5_JS_VER.'$1</script>', $js[1]);
$tail_javascript .= $php_eol.$js[1];
$php_eol = PHP_EOL;
}
}
[/code]
4. $buffer = preg_replace('#(</head>[^<]*<body[^>]*>)#', "$javascript{$nl}$1", $buffer); 하단에 아래 코드 삽입
[code]
$nl = '';
if($tail_javascript)
$nl = "\n";
$buffer = preg_replace('#(</body>[^<]*</html[^>]*>)#', "$tail_javascript{$nl}$1", $buffer);
[/code]
사용방법은 add_javascript()와 같습니다.
[code]
<?php
add_tail_javascript('<script src="'.G5_JS_URL.'/jquery-1.12.4.min.js"></script>', 0);
?>
[/code]
댓글 5개
게시글 목록
| 번호 | 제목 |
|---|---|
| 24318 | |
| 24317 | |
| 24315 | |
| 24309 | |
| 24294 | |
| 24293 | |
| 24277 | |
| 24262 | |
| 24260 | |
| 24253 | |
| 24251 | |
| 24236 | |
| 24233 | |
| 24228 | |
| 24226 | |
| 24221 | |
| 24214 | |
| 24203 | |
| 24201 | |
| 24199 | |
| 24196 | |
| 24195 | |
| 24194 | |
| 24192 | |
| 24191 | |
| 24187 | |
| 24185 | |
| 24183 | |
| 24172 | |
| 24168 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기