자바스크립트로 sms문자 보내기 안드로이드 앰퍼샌드(&) 잘리는 문제

pixgram·2022년 5월 3일
0

프로젝트를 하다가 자바스크립트로 공유메시지를 보내는 기능을 개발하게 되었다. 처음에는 별거 없었다. 그냥 검색한대로 붙여넣기 하니까 잘 되는것 처럼 보였다.

const message = `
    [${shareData.title}]
    ${shareData.description}
    ${shareData.linkUrl}`;

location.href = `sms:${phoneNumber}${
share.checkMobile() === 'ios' ? '&' : '?'
}body=${encodeURIComponent(message)}`;

하지만, 안드로이드에서 문제가 생기기 시작했다.
보통 주소뒤에 앰퍼샌드(&)로 키와 값을 연결하는데, 안드로이드에서 없애 버렸다

http://localhost:8080/post?modal=post-view&seq=220&category=COA02302

이렇게 되길 원했으나, 안드로이드에서..

http://localhost:8080/post?modal=post-view

이렇게 됐다.

이것저것 해보다가 어쩔 수 없이 &문자를 다른 문자로 치환한 다음 받는쪽에서 다시 &문자로 치환하는 방법을 사용했다.

//주는쪽
const message = `
    [${shareData.title}]
    ${shareData.description}
    ${shareData.linkUrl.replace(/&/gi, '_')}`;

location.href = `sms:${phoneNumber}${
share.checkMobile() === 'ios' ? '&' : '?'
}body=${encodeURIComponent(message)}`;

//받는쪽
let search = this.$route.query.search.replace(/_/gi, '&');
profile
Interactive Front-end Developer and WebGL Artist

0개의 댓글