Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 刷新前,Chrome控制台中的脚本不可见,与Firefox配合良好_Javascript_Google Chrome_Firefox_Page Refresh - Fatal编程技术网

Javascript 刷新前,Chrome控制台中的脚本不可见,与Firefox配合良好

Javascript 刷新前,Chrome控制台中的脚本不可见,与Firefox配合良好,javascript,google-chrome,firefox,page-refresh,Javascript,Google Chrome,Firefox,Page Refresh,我必须为我的课程开发一个简短的脚本和报价生成器,但遇到了一个奇怪的问题。该脚本在Firefox上运行良好,但需要页面刷新才能在Chrome上正常运行 我已经尝试将我的所有代码包含在一个用window.onload调用的函数中,但没有任何改变。 我还尝试将脚本标记放在html文件的末尾,但也没有任何更改,仍然存在这个问题 HTML代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> &

我必须为我的课程开发一个简短的脚本和报价生成器,但遇到了一个奇怪的问题。该脚本在Firefox上运行良好,但需要页面刷新才能在Chrome上正常运行

我已经尝试将我的所有代码包含在一个用window.onload调用的函数中,但没有任何改变。 我还尝试将脚本标记放在html文件的末尾,但也没有任何更改,仍然存在这个问题

HTML代码:

<!DOCTYPE html>
<html>

<head>
 <meta charset="utf-8">
 <meta http-equiv="X-UA-compatible" content="IE-edge">
 <meta name="viewport" content="width=device-width, initial-scale-1">
 <script type="text/javascript" src="script.js"></script>

 <title>Citations pour héros et héroïnes</title>
</head>
<body>
</body>
</html>

对赫罗斯和赫罗伊内斯的引用
JS代码:

// Tableaux de données
const firstSFArray = ["Je suis", "Je serais", "J'ai été"];
const secondSFArray = ["un pilote", "un aventurier", "un explorateur", "un 
agent", "un chercheur", "un colon"];
const thirdSFArray = ["de Vénus", "de Mars", "d'Alpha Centauri", "des tréfonds de la Galaxie", "du Néant"];

const firstFanArray = ["Je suis", "Je serais", "J'ai été"];
const secondFanArray = ["un marchand", "un guerrier", "un barbare", "un 
sorcier", "un élémentaire", "un voleur"];
const thirdFanArray = ["d'Hyrule", "de Cimmérie", "des Terres du Milieu", "de Poudlard", "du Pandémonium", "de l'Autre Monde"];

// Génération de la citation
let result;

function generator(array1, array2, array3) {
  const random1 = array1[Math.floor(Math.random() * array1.length)];
  const random2 = array2[Math.floor(Math.random() * array2.length)];
  const random3 = array3[Math.floor(Math.random() * array3.length)];

result = random1 + " " + random2 + " " + random3;
}

// Question à l'utilisateur

while (true) {
  const firstQuestion = prompt("Une nouvelle citation O/N ?").toLowerCase();

  if (firstQuestion === 'o') {
    const secondQuestion = parseFloat(prompt('Combien de citations souhaitez-vous (1 à 5) ?', "1"));

      if (secondQuestion <= 5) {
        const thirdQuestion = prompt("Univers Science-Fiction (S) ou Fantastique (F) ?").toLowerCase();

          if (thirdQuestion === 'science-fiction' || thirdQuestion === 's') {

              for (let x = 0; x < secondQuestion; x++) {
                generator(firstSFArray, secondSFArray, thirdSFArray);
                const quote = result;
                console.log(quote);
              }
          } else if (thirdQuestion === 'fantastique' || thirdQuestion === 'f') {

              for (let x = 0; x < secondQuestion; x++) {
                generator(firstFanArray, secondFanArray, thirdFanArray);
                const quote = result;
                console.log(quote);
              }
          }
      }
  } else if (firstQuestion === 'n') {
    break;
  }
}
//Tableaux de données
const firstSFArray=[“Je suis”、“Je serais”、“J'aiété”];
const secondSFArray=[“无人驾驶”、“无人复仇”、“无人探索”、“无人驾驶”
代理人“,”联合国chercheur“,”联合国colon“];
const thirdSFArray=[“德维努斯”、“德马尔斯”、“半人马座阿尔法”、“德拉加拉克斯之旅”、“德纳特”];
const firstFanArray=[“Je suis”、“Je serais”、“J'aiété”];
const secondFanArray=[“un marchand”、“un guerrier”、“un barbare”、“un”
sorcier“,”unélémentaire“,”un voleur“];
第三方阵常数=[“海拉尔”、“Cimmérie”、“环境地球”、“Poudlard”、“du Pandémonium”、“de l'Autre Monde”];
//引证理由
让结果;
函数生成器(阵列1、阵列2、阵列3){
const random1=array1[Math.floor(Math.random()*array1.length)];
const random2=array2[Math.floor(Math.random()*array2.length)];
const random3=array3[Math.floor(Math.random()*array3.length)];
结果=随机数1+“”+随机数2+“”+随机数3;
}
//利用率问题
while(true){
const firstQuestion=prompt(“新引用是否正确?”).toLowerCase();
如果(第一个问题=='o'){
const second question=parseFloat(提示('cobien de citations souhaitez vous(1á5)'),“1”);

如果(第二个问题您的脚本似乎运行得很好。在Chrome开发工具中测试过,它可以工作。在没有开发工具的情况下测试过(与您提供的示例完全相同),它也可以工作。我的开发工具唯一抱怨的是“未捕获的语法错误:无效或意外的标记”,因为在
“un
(第2行)之后有一个换行符,但我认为这是因为StackOverflow的格式?

谢谢。是的,它是堆栈格式。当你用Chrome打开页面时,脚本直接工作?你不需要重新加载它就能看到不同的引号?没错。我将你的html保存为“test.html”,将你的js保存为“script.js”“,加载了它,它在第一次加载时就工作了。Chrome 71.0.3578.98(官方版本)(64位)同一版本…好的,真的很奇怪。我安装了ghostery。他能阻止这样的脚本吗?没有线索!尝试禁用它运行吗?可能是在匿名中?然后暂时禁用该fcker;)。