현재창 url를 제이쿼리로 바꿀 수 있는 기능이 있나요? 채택완료
현재창이 https://www.naver.com 라고 가정할때
'&brand_nm=2' 라는걸 추가해서 https://www.naver.com&brand_nm=2 되도록
만들고 싶은데 제이쿼리로 이런게 가능한지 알고 싶어요~
네이버는 예시 이고 내가 보고있는 현재창 URL + &brand_nm=2 이 부분만 들어가면 되거든요~
감사합니다~
답변 4개
let url = location.href;
url = location.href + '&brand_nm=2';
location.href = url;
답변에 대한 댓글 6개
alert(url);
-> location.href = url;
로 수정하였습니다.
let url = location.href;
url = location.href + '&brand_nm=2';
if (url.indexOf('brand_nm') < 0)
location.href = url;
</script>
방금 주신 내용은 링크가 바뀌지 않았습니다~ ㅠㅠ
let url = location.href;
if(url.indexOf('&brand_nm=2')<0){
url = location.href + '&brand_nm=2';
location.href = url;
}
</script>
알려주신 내용대로 스스로 이렇게 저렇게 변형해서 해보니까 제대로 작동합니다!!!
감사합니다. 오늘 하루종일 이거에 매달렸는데 알려주신 덕분에 쉽게 끝낼 수 있었습니다.
불금 즐거운 주말보내세요!
댓글을 작성하려면 로그인이 필요합니다.
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
php 로도 가능한데 제이쿼리를 말씀하셔서 답변드립니다.
function addParameter( $url: String, $param: Object ): String
{
var url: String = $url.split( "?" )[ 0 ];
var param: URLVariables = new URLVariables( $url.split( "?" )[ 1 ] );
var prop: String;
for( prop in $param )
param[ prop ] = $param[ prop ];
if( param.toString().length > 1 )
url += "?" + param.toString();
return url;
}
일때
타입1
var url: String = "http://도메인.com/stratus.php";
var param: Object = {};
param.command = "add";
param.peerid = "1234";
trace( addParameter( url, param ) );
// 결과
// http://도메인.com/stratus.php?peerid=1234&command=add
타입2
var url: String = "http://도메인.com/stratus.php?a=b";
var param: Object = {};
param.command = "add";
param.peerid = "1234";
trace( addParameter( url, param ) );
// 결과
// http://도메인.com/stratus.php?peerid=1234&a=b&command=add
답변에 대한 댓글 1개
혹시 http://도메인.com/stratus.php 이 부분에서 현재창으로 대체할 수 있는게 있을까요?
왜 꼭 현재창이여야 하냐면 /도메인/0000001234/&brand_nm=2 이런식으로 숫자부분이 변수라 특정 버튼마다 숫자가 바뀌거든요~ 고도몰에서는 치환코드로 되어있어서 제가 수정할 수 없는 부분이라 최대한 우회해서라도 방법을 찾는 중입니다.
댓글을 작성하려면 로그인이 필요합니다.
<a href=" https://www.naver.com?brand_nm=2&brand_size=2">네이버 브랜드 NO2</a>
태그 자체에 걸어도 되구요,
jquery로 하려면
</p>
<p><button type="button" id="btnN">네이버</button></p>
<p> </p>
<p><script src="<a href="https://code.jquery.com/jquery-2.2.4.min.js"" target="_blank" rel="noopener noreferrer">https://code.jquery.com/jquery-2.2.4.min.js"</a> ></script></p>
<p><script>
$("#btnN").click(function(){
$(location).attr("href", "<a href="https://www.naver.com?brand_nm=2") " target="_blank" rel="noopener noreferrer">https://www.naver.com?brand_nm=2") </a>
}
</script></p>
<p>
태그에 아이디 or 클래스를 달아서 클릭시 이동하겠금 하면 됩니다.
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
let url = location.href;
url = location.href + '&brand_nm=2';
location.href = url;
</script>
알려주신대로 시도해봤지만 링크창이 바뀌지 않고 '현재창URL + &brand_nm=2'
내용으로 알림창이 뜨네요~ 해결은 안됐지만 그래도 감사합니다~!