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개
게시글 목록
| 번호 | 제목 |
|---|---|
| 24149 | |
| 24140 | |
| 24133 | |
| 24125 | |
| 24119 | |
| 24109 | |
| 24105 | |
| 24101 | |
| 24093 | |
| 24089 | |
| 24077 | |
| 24074 | |
| 24071 | |
| 24070 | |
| 24067 | |
| 24056 | |
| 24050 | |
| 24046 | |
| 24043 | |
| 24040 | |
| 24037 | |
| 24036 | |
| 24035 | |
| 24034 | |
| 24021 | |
| 24017 | |
| 24005 | |
| 24002 | |
| 23990 | |
| 23980 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기