我的Cookie代码无法在Google Chrome上运行 [英] My cookie code wont work on Google chrome

查看:75
本文介绍了我的Cookie代码无法在Google Chrome上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它可以根据要求在其他浏览器上运行,但在Chrome上它不会,我不知道如何解决它...我猜它与Googles cookie政策有关?

我尝试将音频的当前时间写入cookie,并且在切换页面/刷新页面时,将音频时间调到最后一点,从cookie中获取值。











< body onload =playAudio()onunload =setCookie()> 
< audio id =asrc =a.mp3>< / audio>

< button onclick =showCookie()type =button> Prikazi cookie< / button>
< button onclick =playAudio()type =button> Play< / button>
< button onclick =resetK()type =button>重置< / button>





< pre lang =Javascript>< script>
function setCookie(){
var y = document .getElementById( a);
var ee = y.currentTime;
document .cookie = ee;
}
function showCookie(){
alert( < span class =code-string> Cookie je: + document .cookie);
}
function playAudio(){
var p = < span class =code-sdkkeyword> document .cookie;
var x = document .getElementById( a);
if (x.duration!= p){
x.currentTime = document .cookie;
} else {x.currentTime = 0 ;}
x.play( );
}
function resetK(){
document .cookie = 0 ;
}< / script>





我尝试了什么:



我试过改变cookie的名字,但也没有运气......

解决方案

检查这个< a href =http://stackoverflow.com/a/12618175/1147428> google chrome - 无法在Javascript中设置Cookie [ ^ ]

看起来您必须在服务器中托管该文件并进行测试。


It works on other browsers, as requested, but on Chrome it just wont, i have no idea how to fix it...i guess it has something to do with Googles cookie policy?
I try to write the current time of the audio, to the cookie, and than when switching pages/refreshing page, get the audio time to the point where it was last, getting the value from the cookie.





<body onload="playAudio()" onunload="setCookie()">
		<audio id="a" src="a.mp3" ></audio>
		
		<button onclick="showCookie()" type="button">Prikazi cookie</button>
		<button onclick="playAudio()" type="button">Play</button>
		<button onclick="resetK()" type="button">Reset</button>



<script>
		function setCookie(){
			var y = document.getElementById("a");
			var ee = y.currentTime;
			document.cookie=ee;
		}
		function showCookie(){
			alert("Cookie je: " + document.cookie);
		}
		function playAudio(){
			var p = document.cookie;
			var x=document.getElementById("a");
			if (x.duration!=p){
				x.currentTime = document.cookie;
			}else {x.currentTime = 0;}
			x.play();
		}
		function resetK(){
			document.cookie = 0;
		} </script>



What I have tried:

I have tried changing names of the cookie, but had no luck with that too...

解决方案

check this google chrome - Cannot set cookies in Javascript [^]
Looks like you will have to host the file in the server and test.


这篇关于我的Cookie代码无法在Google Chrome上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆