iframe location 이동문제

김정현·2024년 8월 29일
0

포트폴리오

목록 보기
7/8

우선 refer 을 사용하여 요청을 보낸 url 을 추출할 수 있었다.

        String referer = request.getHeader("Referer");  // 요청 발생시킨 주소 가져옴

이렇게 추출한 url을 통해 iframe창을 이동 시킬 예정이였다.

(해당 사진 아래 댓글 창이 iframe)

   if (referer != null && referer.contains("board/comment/")) {
            String redirectUrl = utils.redirectUrl(String.format("/board/comment/%d?comment_id=%d", commentData.getBoardData().getSeq(), commentData.getSeq()));

            String script = String.format("location.replace('%s');", redirectUrl);

            System.out.println("script12321" + script);
            model.addAttribute("script", script);

            return "common/_execute_script";
        }

그러나 댓글은 추가 되지만 url이 이동되지 않았다.
이유는 iframe에 target 설정이 올바르지 않기때문이다 .
iframe 댓글의 레이아웃을 적용해야했다.

0개의 댓글