function myFunction(){
if (site == null || variable == undefined) {
var site = prompt("Please enter a valid url:", "http://");
document.cookie = 'Your bookmark is: '+ site;
alert(unescape(document.cookie));
document.getElementById("p1").innerHTML = '<a class="txt2" href="' + site + '" target="myframe">' + site + '</a>';
}
else {
alert('yey its working');
}
}
Variables declared within a JavaScript function, become LOCAL to the
function
理想的方法是检查 document.cookie 而不是变量 -
function myFunction(){
if ( document.cookie == '') {
var site = prompt("Please enter a valid url:", "http://");
document.cookie = 'Your bookmark is: '+ site;
alert(unescape(document.cookie));
document.getElementById("p1").innerHTML = '<a class="txt2" href="' + site + '" target="myframe">' + site + '</a>';
}
else {
alert('yey its working');
}
}
myFunction();