v.1 : 게시판이 붙을 경우 검색 안됨
document.querySelectorAll(".content").forEach(content => {
content.innerHTML = content.innerHTML.replace(/#([\w가-힣_]+)/g, function (match, tag) {
return `<a href="?search=${tag}">${match}</a>`;
});
});
#hashtag
v.2 : 글 본문에서 검색 안됨
document.querySelectorAll(".content").forEach(content => { // 현재 페이지 URL에서 마지막 경로(게시판 ID) 가져오기 const pathParts = window.location.pathname.split("/").filter(Boolean); // 빈 값 제거 const boardId = pathParts.length > 0 ? pathParts[pathParts.length - 1] : ""; // 마지막 경로 값 (게시판 ID) console.log(boardId); // 변수명 수정 content.innerHTML = content.innerHTML.replace(/#([\w가-힣_]+)/g, function (match, tag) { if (boardId) { return `<a href="./${boardId}/?search_keyword=${tag}&search_target=title_content">${match}</a>`; } else { return `<a href="./?search_keyword=${tag}&search_target=title_content">${match}</a>`; } }); });
v.3
document.querySelectorAll(".content").forEach(content => { // 현재 페이지 URL에서 경로 가져오기 const pathParts = window.location.pathname.split("/").filter(Boolean); // 빈 값 제거 let boardId = pathParts.length > 0 ? pathParts[0] : ""; // 첫 번째 경로(게시판 ID) // 글 번호(두 번째 경로)가 있으면 제거 (ex: threads/471363 → threads/) if (pathParts.length > 1 && !isNaN(pathParts[1])) { boardId = pathParts[0]; // 첫 번째 경로만 남기기 } console.log("게시판 ID:", boardId); // 디버깅용 content.innerHTML = content.innerHTML.replace(/#([\w가-힣_]+)/g, function (match, tag) { if (boardId) { return `<a href="/${boardId}/?search_keyword=${tag}&search_target=title_content">${match}</a>`; } else { return `<a href="/?search_keyword=${tag}&search_target=title_content">${match}</a>`; } }); });
참조
https://codepen.io/nikolett_codes/pen/daWxea
https://xe1.xpressengine.com/?mid=download&package_id=22753681
https://xe1.xpressengine.com/index.php?mid=download&package_id=22753695
제목 | 날짜 | ||
---|---|---|---|
해시태그 자바스크립트 | 2025/02/01 | 2 | |
20 | 스크랩 ec_imin | 2025/01/31 | 3 |
19 | 스크랩(threads) v1 [1] | 2025/01/31 | 2 |
18 | 새로고침 없는 좋아요 버튼 [3] | 2025/01/31 | 9 |
17 | 더보기 php 코드 | 2025/01/31 | 3 |
16 | 글추천 버튼 | 2025/01/31 | 10 |
15 | 글보기에서 바로 비밀글 변경하는 방법 [4] | 2025/01/30 | 10 |
14 | 글보기에서 바로 비밀글 설정하는 방법 [1] | 2025/01/30 | 3 |
13 | [Tips] 라이믹스 모든 글 최신글 가져오기 코드 | 2025/01/29 | 6 |
12 | [Tips] 라이믹스 특정 게시판 글 가져오기 | 2025/01/29 | 9 |
11 | [구인] [모집] 💻 다국어지식나눔 조인어스월드 웹 IT 봉사단 동아리 6기를 모집합니다! (~ 2025.02.14) | 2025/01/28 | 47 |
10 | 밍구님의 따뜻한 한마디 | 2025/01/27 | 11 |
9 | 라이믹스 debugPrint | 2025/01/24 | 8 |
8 | 라이믹스 게시판 스크랩 기능 | 2025/01/21 | 9 |
7 | 라이믹스 후하니 스티커 모듈 | 2025/01/21 | 1 |
6 | [미입금] 새로운 사이트에 후하니님의 스티커 모듈 설치 의뢰 [1] | 2025/01/21 | 2 |
5 | [레거시코드] pointhistory 모듈 유지보수 방법 | 2025/01/16 | 9 |
4 | [구인] <초기 창업팀 팀원모집(항공/기상 분야)> : Data Scientist (Part-Time) | 2025/01/08 | 27 |
3 | [대기] 모듈 개발 추가 요청 | 2025/01/06 | 17 |
2 | [XE] 인기검색어 모듈+애드온+위젯 패키지 (PHP8수정버전) 문의 드립니다 [1] | 2025/01/06 | 5 |