변수의 문자열을 쿠키에 넣고 싶습니다. (내용으로) 현재 쿠키가 설정되고 이름은 username입니다. (그 부분은 작동합니다) 변수의 내용은 쿠키에 저장되지 않습니다. 여기에 내가 가진 것이있다. 나는 비슷한 질문을 한 번 보았고 그 대답은 그다지 효과가 없었다. 내가 문자열이다시피변수를 쿠키에 넣는 방법은 무엇입니까?
var sharedContent = sharedURL;
var sharedURL = "http://www.example.com/";
function getUrl() {
window.location.href= sharedURL;
createCookie();
}
function createCookie() {
document.cookie = "username="+sharedContent+"; expires=Wed, 1 Jan 2025 13:47:11 UTC; path=/"
}
을 사용하고 가능하기 때문에, 내가 JS를 사용하여 조금 새로운입니다.
HTML :
<link href='https://fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'>
<a href="https://www.minds.com/newsfeed"><div class="button" onclick="getUrl(); "><img src="icon.png" width="16">Share</div></a>
,
에 변화하고있다. 변수 정의는 게양되지 않습니다. 따라서 sharedURL은 첫 번째 var와 두 번째 sharedContent 예제 여야합니다. https://jsbin.com/zomewucomo/edit?html,js,console –