私は変数の文字列をクッキーに入れたいと思います。 (内容として)現在、クッキーは設定されていて、その名前は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と2番目のsharedContentの例にする必要があります。https://jsbin.com/zomewucomo/edit?html,js,console –