脚本适用于chrome,但不适用于firefox或IE [英] Script works in chrome but not in firefox or IE

查看:127
本文介绍了脚本适用于chrome,但不适用于firefox或IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下脚本仅适用于Google Chrome,并且无法在Firefox或IE上运行





The below script works perfectly fine on Google Chrome only and doesn't work on Firefox or IE


//I created the script at the bottom of the body to change select dropdown based on currently selected mainheading value.
//old method tried to use scriptlets mixed with javascript, but it's easier to do this with javascript.
const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('mainHeading'); 
//if mainHeading parameter is null or equal to  Operations show  Operations dropdown
if(myParam === ' Operations' || myParam === null) {
	document.getElementById('mainHeading').value = ' Operations';
}else{
	document.getElementById('mainHeading').value = ' Future Plans';
}





我的尝试:



如果我将if语句的顺序更改为以下,则下拉列表中唯一可用的选项是Operation,第二个选项Future Plans从不显示





What I have tried:

If I change the order of the if statement to the below, then the only option available in the drop down list is "Operation" and the second option "Future Plans" never shows up

var urlParams = new URLSearchParams(window.location.search);
var myParam = urlParams.get('mainHeading'); 
//if mainHeading parameter is null or equal to Operations show Operations dropdown
if(myParam ==='Future Plans'){
	document.getElementById('mainHeading').value = 'Future Plans';
}else{
	document.getElementById('mainHeading').value = 'Operations';

推荐答案

URLSearchParams - Web API | MDN [ ^ ]



底部有一个兼容性列表。
URLSearchParams - Web APIs | MDN[^]

There is a compatibility list at the bottom.


这篇关于脚本适用于chrome,但不适用于firefox或IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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