Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.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 谷歌浏览器识别弹出窗口_Javascript_Html - Fatal编程技术网

Javascript 谷歌浏览器识别弹出窗口

Javascript 谷歌浏览器识别弹出窗口,javascript,html,Javascript,Html,我有一行Javascript: if (true){ $('#custom-tag').html('HTML'); } else { $('#custom-tag').html('DifferentHTML'); } 如果变量为yes,它将在启动时运行此html代码。 如果变量不是yes,那么它将在启动时运行这一行html。 我该怎么做 编辑:恐怕我忘了说,我想用这个来检测你的浏览器。如果使用chrome,它将不会输出HTML。如果使用chrome以外的浏览器,它将输出HTML 编

我有一行Javascript:

if (true){ 
  $('#custom-tag').html('HTML');
} 
else {
  $('#custom-tag').html('DifferentHTML');
}
如果变量为yes,它将在启动时运行此html代码。 如果变量不是yes,那么它将在启动时运行这一行html。 我该怎么做

编辑:恐怕我忘了说,我想用这个来检测你的浏览器。如果使用chrome,它将不会输出HTML。如果使用chrome以外的浏览器,它将输出HTML

编辑2:我有这个代码。我需要修复这个弹出窗口,确定它是否是铬

$(函数(){
$('#in')。on('keyup',function(){
验证();
});
});
函数验证(){
var x=$('#in').val();
if(navigator.userAgent.indexOf(“Chrome”)!=-1){
$('#result').html('Chrome');
}否则{
$('#result').html('');
}
}

浏览器

尝试使用
三元运算符的单行代码段

// Check if not chrome
if(!$.browser.chrome){
    // If its variable.
    $('#custom-tag').html( (variable == 'yes') ? 'html' : 'different html' );
}

// If its checkbox.
$('#custom-tag').html( $('#checkboxId').is(":checked") ? 'html' : 'different html' );
它在这里工作

var name;
if(name.checked == true){
 $('#custom-tag').html('HTML');
}else{
 $('#custom-tag').html('DifferentHTML'); 
}
您还可以通过定义var x=''来实现这一点;在脚本的开头,然后根据您的其他脚本语句,它将获得值true或false。然后您需要检查x='',或者不检查。就这样

$(函数(){
$('#in')。on('keyup',function(){
验证();
});
});
函数验证(){
var x=$('#in').val();
如果(x==“x”){
$('#result').html('x entered');
}否则{
$('#result').html('输入x以外的内容');
}
}

您可以通过以下方式检查其chrome浏览器:

if( navigator.userAgent.toLowerCase().indexOf('chrome') > -1 ){ 
  // chrome, do nothing
} 
else {
  // not chrome put html
  $('#custom-tag').html('HTML');
}

请更具体地说明检查的变量的含义我不理解你的问题。。我知道这是关于有条件的。。。你所说的
变量未被选中是什么意思?
启动时的
?@Akidus,检查我的答案中的变量/复选框条件我认为这很接近。我需要它来检测浏览器。我做了一个编辑。检查有chrome浏览器检查的答案没有任何检查,我需要编辑它。。。谢谢你的回复。这可能有用,我正在尝试将其添加到我的代码中。我还在学习js。我需要以某种方式将其融入我的代码中,而不会弄乱弹出窗口。我在识别浏览时如何做到这一点?这可能会奏效。如何确定您是否使用chrome?这是一个不同的问题,它已经有了答案:希望它有帮助:)@esteban rincon这可能有用,但我仍在学习JS,所以我不确定如何将其放入我的代码中。将我提供的代码片段if(x=“x”)更改为if(“/\bCrOS\b/”。test(navigator.userAgent)谢谢。我在上面添加了一个片段,以防有人需要。
if( navigator.userAgent.toLowerCase().indexOf('chrome') > -1 ){ 
  // chrome, do nothing
} 
else {
  // not chrome put html
  $('#custom-tag').html('HTML');
}