Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Saturday, February 13, 2021

The script has an unsupported MIME type ('text/html').

ServiceWorker: The script has an unsupported MIME type (chrome-extension) 


The Error is showing because of the incorrect path and service worker is not accessible.

Path defined for js is not correct, might be you have taken relative path and this is vary on different pages.

Replacing:

'service-worker.js'

with:

'/service-worker.js' OR './service-worker.js'

in (navigator.serviceWorker.register('/service-worker.js')


The service worker file is not present at http://domain.com/service-worker.js so the server is returning index.html instead. Then the registration function has no idea of what to do with a index.html file and tells you that the MIME-type is not correct. 

A quick fix would be to copy the service-worker.js file to the public folder so that when you hit http://domain.com/service-worker.js you see the file in the browser. 

Remember to go to ChromeDev > Applications > ServiceWorkers and hit Unsubscribe. in order to remove the errored one. Remember also disable cache 

Wednesday, February 3, 2021

window.location.href not working - asp.net

 window.location.href not working


If we are calling function through a submit button. This may be the reason why the browser does not redirect. It will run the code in the function and then submit the page instead of redirect. 

In this case Either
1. change the type tag of your button to button
        2. you just need to add "return false;" at the bottom of your function

Tuesday, January 28, 2020

whats the difference between == and === ?

The difference between == and === is that:


1. == converts the variable values to the same type before performing comparison. This is called type coercion.
2. === does not do any type conversion (coercion) and returns true only if both values and types are identical for the two variables being compared.

Example:

  1. var one = 1;
  2. var one_again = 1;
  3. var one_string = "1"; // note: this is string
  4. console.log(one == one_again); // true
  5. console.log(one === one_again); // true
  6. console.log(one == one_string); // true. See below for explanation.
  7. console.log(one === one_string); // false. See below for explanation

Wednesday, October 6, 2010

Javascript: Function to get Cookies values

function getCookiesValue(objCkNm)
{
var beginindex, endindex, result, num;
num = objCkNm.length;
beginindex=document.cookie.indexOf(objCkNm) + num +1 ;
endindex=beginindex;
//while we haven't hit ";" and it's not end of cookie
while (document.cookie.charAt(endindex)!=";" && endindex <= document.cookie.length)
endindex++

//result contains "JavaScript Kit"
result=document.cookie.substring(beginindex,endindex)
return result;
}

Javascript: function to check that number is numeric

function IsNumeric(strString)
{
// check for valid numeric strings
var strValidChars = "0123456789.-";
var strChar;
var blnResult = true;

if (strString.length == 0) return false;

// test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
blnResult = false;
}
}
return blnResult;
}

Javascript: Email Validation function

function ValidateEmail(str)
{
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1)
{
alert("The eMail address '@' convention appears to be invalid.")
return false
}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
{
alert("The eMail address '@' convention appears to be invalid.")
return false
}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("The eMail address 'dot' convention appears to be invalid.")
return false
}

if (str.indexOf(at,(lat+1))!=-1)
{
alert("The eMail address '@' convention appears to be invalid.")
return false
}

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
{
alert("The eMail address 'dot' convention appears to be invalid.")
return false
}

if (str.indexOf(dot,(lat+2))==-1)
{
alert("The eMail address 'dot' convention appears to be invalid.")
return false
}

if (str.indexOf(" ")!=-1)
{
alert("The eMail address spacing convention appears to be invalid.")
return false
}
return true
}

Thursday, April 8, 2010

Populate Date DropDown using Javascript

Set the values of Dropdown list of a date:-

There are three dropdown lists for each Day, Month And Year.  we fill through javascript with following way:

        var date ="11/23/2010"; //Format- MM/DD/YYYY
        var mm = date.substring(0,2);
        var dd = date.substring(3,5);
        var yy = date.substring(6,10);
       
        document.getElementById("ddlDay").value=dd;
        document.getElementById("ddlMonth").value=mm;
        document.getElementById("ddlYear").value=yy;

Thursday, February 11, 2010

Get value of radiobuttonlist, javascript

Call the javascript function at page_load()

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
rbtnList.Attributes.Add("onclick", "javascript:checkOthersOption('" + rbtnList.ClientID + "');");
}
}

And Add javascript to the aspx page


function checkOthersOption(id)
{
var radioList = document.getElementById(id);
var radio = radioList.getElementsByTagName('input');
alert(radio.length);
for (var i = 0; i < radio.length; i++)
{
if(radio[i].type =="radio")
{
if (radio[i].checked)
alert(radio[i].value);
}
}

}

Saturday, February 6, 2010

Javascript Date validation function

function checkDate(ddlDay,ddlMonth,ddlYear)
{

var d=document.getElementById(ddlDay).value;
var m=document.getElementById(ddlMonth).value;
var y=document.getElementById(ddlYear).value;

var yl=1900; // least year to consider
var ym=2100; // most year to consider
var flag = true;

if (m<1>12) flag=false;
if (d<1>31) flag=false;
if (yym) flag=false;
if (m==4 || m==6 || m==9 || m==11)
if (d==31) flag=false;
if (m==2)
{
var b=parseInt(y/4);
if (isNaN(b)) flag=false;
if (d>29) flag=false;
if (d==29 && ((y/4)!=parseInt(y/4))) flag=false;
}

if(flag)
{
return (true);
}
else
{
return (false);
}

return(true);
}