지금 이온디에서 어떤 주제의 글이 새로 올라왔는지 확인해보세요.
글 등록하기 | 내글 관리하기 | 연재글 | 보관함
해시태그 자바스크립트
이온디
첨부파일 https://imweb.eond.com/xe/471359

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


코멘트 0
접기/펴기 | 댓글 새로고침
 
 
Total 21 articles in 1 / 2 pages
번호 제목 제목 날짜날짜 조회 수
현재글 새글 해시태그 자바스크립트 수정 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

해시태그 디렉터리

지금 이순간