How to detect whether browser supports :invalid pseudoclass? [duplicate] - javascript

This question already has answers here:
Test if a browser supports a CSS selector
(5 answers)
Closed 8 years ago.
I tried to use Modernizr, but it seems not to support this feature detection.
I also read that it is difficult or even inmpossible to access pseudoclasses from javascript, because they are not part of DOM. So, after surfing the web I found no relevant information.
I need an easy solution without the need to download heavy libraries.
Can anybody help me with this?
Thanks

Trap an error from querySelector or matches, which parses the selector and throws an error if it is not valid:
function invalid_pseudoclass_support () {
var support = true;
try {
document.querySelector(':invalid');
} catch (e) {
support = false;
}
return support;
}

Related

Unsafe assignment to innerHTML [duplicate]

This question already has an answer here:
Best way to purge innerHTML from a Firefox Extension
(1 answer)
Closed 2 years ago.
I was trying to get an add on for Firefox signed by Mozilla so I could use it on the stable version of firefox and I'm getting this validation issue.
Can someone help me understand what it is?
Unsafe assignment to innerHTML
Warning: Due to both security and performance concerns,
this may not be set using dynamic values which have not been adequately sanitized.
This can lead to security issues or fairly serious performance degradation.
datetime.js line 4 column 5
function updateClock(){
var doc=window.content.document
var dt = new Date();
doc.getElementById("datetime").innerHTML = dt.toLocaleTimeString();
}
setInterval(updateClock, 0);
dt.toLocateTimeString() return a String instead of HTML.
Instead of, use innerText or textContent:
doc.getElementById("datetime").innerText = dt.toLocaleTimeString();
doc.getElementById("datetime").textContent = dt.toLocaleTimeString();

Checking if template literals are available in script [duplicate]

This question already has an answer here:
creating an error message if browser does not support ES6 Template Literals
(1 answer)
Closed 4 years ago.
I'm trying to find a way to check if template-literals in JS are supported in the given browser. The idea is to pass them different scripts created by Babel if the browser doesn't support ES6 features. So I'm trying:
function check_es6() {
try { `foo` }
catch (e) { return false; }
return true;
}
alert(check_es6());
However, on my old iPhone I get:
Invalid character On line 141 of
https://m.xxx.org/2018/js/app.js on 1 page.
Seen in Mobile Safari 7. Last seen 20 minutes ago. Occurred once so far. Occurred before page load.
Line 141 is:
try { `foo` }
Is there a better way to do what I need?
OK, so managed to work it out myself :)
try { eval("`foo`"); }
This correctly shows "false" now when the browser doesn't support template literals, and "true" in later browsers that do.

javascript events not working with Chrome Extension , why ! :/ [duplicate]

This question already has answers here:
Port error while changing chrome extension from manifest v1 to v2
(2 answers)
Closed 8 years ago.
HTML // code
input id ="submit_btn" type="submit" value="find" onclick="goto();"
Javascript / code
function goto()
{
if (document.getElementById("s_keyword").value != "") {
var url = ("https://www.youtube.com/results?search_query=" + document.getElementById("s_keyword").value);
var site = window.open(url, '_blank');
site.focus();
}
};
it never enters into goto function !
Chrome extensions don't support inline events. Add the event listener in your JavaScript, and it'll be fine:
document.getElementById('submit_btn').addEventListener('click', goto);
You may want to avoid using goto as your function's name too. It may be a reserved keyword.

document.createElement throwing error in IE 8. This command is not Supported ERROR [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Javascript doesn't work in IE8
I have the following code
var ind=1;
try
{
rdo = document.createElement('<input type="radio" name="radioOptions" />');
}
catch(err)
{
rdo = document.createElement('input');
}
rdo.setAttribute('type','radio');// error
rdo.setAttribute('name','radioOptions');
rdo.id = 'radioOption_'+ind;
rdo.value = ind;
After a thorough checkup this line is throwing error on IE 8
rdo.setAttribute('type','radio')
and a strange fact is that when it is on the local system its not doing that.
I am dynamically adding this radio input to the form. And the Doc type i have set to
<!doctype html>
Any Idea what should work for all Browsers including the ASS HOLE IE
You can not change the type of input elements in IE with setAttribute(). You could try with rdo.type = 'radio' (which should work) or (ugh) innerHTML.
Also, document.createElement() is used with the element's name, i.e. input. It is not like $() in jQuery or similar libraries.

How to convert all() function to work crossbrowser [duplicate]

This question already has answers here:
Replacement of .all() function for Browsers other than IE
(2 answers)
Closed 8 years ago.
I have below code. I want to convert this as cross browser compatible. As all() is IE only function i need to convert this. Please help me.
for(j=1,oTblRows=tblSource.rows,tLen=oTblRows.length;j<tLen;j++){
o=oTblRows[j].all("center");
if(o && (o.innerText === selCenter.value)){
$(oTblRows[j]).show();
}
else{
$(oTblRows[j]).hide();
}
}
I believe this is what you want. We want to match all elements with the id of "center" within the current row.
o=jQuery("#center", oTblRows[j])

Categories

Resources