![](/img/trans.png)
[英]How to fix following error: InvalidArgumentException: Auth guard [jwt] is not defined
[英]How to fix a not defined javascript error?
我對Java語言還很陌生,我想做的就是在單擊鏈接后立即設置一個cookie。 當我從鏈接返回到上一頁時,我希望頁面自動刷新並通過顏色通知用戶以顯示他們剛剛單擊的鏈接。 我使用此示例來指導我http://webdesign.about.com/od/cookies/a/aa083198.htm 。 但是我還是不明白。
下面的代碼是我所擁有的。 問題是,一旦我單擊鏈接,螢火蟲就會彈出錯誤“ getLink not defined”。 同樣通過Firefox上的Web開發人員,即使我從Html調用它也似乎實際上沒有設置我的cookie,並且還展示了Html中調用函數的最重要部分。
我在setCookie中擁有的videoId是一個在我的代碼中其他位置定義的php變量。 如果有人能指出我正確的方向,我將不勝感激。 謝謝!
<head>
<script language="text/javascript">
var cookie_name = "watched";
function setCookie(cookie_name,cookie_value)
{
if (document.cookie!="") {
index = document.cookie.indexOf(cookie_name);
} else {
index = -1;
}
if (index == -1) {
var finish = 7200;
var cookie_value = videoId + "; expires=" + finish;
document.cookie=cookie_name + "=" + cookie_value;
}
}
function getLink(cookie_value) {
if (document.cookie) {
index = document.cookie.indexOf(cookie_value);
if (index != -1) {
colorLinks;
}
else{
//alert("No color");
}
}
return colorLinks;
}
function colorLinks()
{
$('#' + videoId).css('background-color: pink');
}
</script>
</head>
<body onLoad=window.refresh>
<div id="page">
echo '<a href="' . $link . '" onclick="setCookie(); return true;">' . $this->Links
這根本不符合邏輯:
function getLink(cookie_value) {
if (document.cookie) {
index = document.cookie.indexOf(cookie_value);
if (index != -1) {
colorLinks; // you mean colorLinks(); ???
}
else {
//alert("No color");
}
}
// why return a function that sets color instead of just calling it?
return colorLinks;
}
幸運的是,沒有什么叫做window.refresh
(除非您自己創建了它),否則您將永遠循環
videoId
的值 setCookie(cookie_name,cookie_value);
設置cookie。 請閱讀有關cookie的信息: http : //www.quirksmode.org/js/cookies.html
<script type = "text/javascript">
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.