Find and delete cookie with javascript [duplicate] - javascript

This question already has answers here:
How to delete a cookie?
(13 answers)
Closed 6 years ago.
How would like to with javascript find a cookie that starts with 'AzureAppProxyAccess' and delete that cookie? It always has a series of random numbers at the end of the name. It is in the same domain so I have access to it.
This is what I have tried with jquery but I would like just javascript.
for (cookie in $.cookie()) {
if(cookie.substring(0, 19) === "AzureAppProxyAccess") {
$.removeCookie(cookie);
}
};

You can use indexOf in strings.
cookie.indexOf('AzureAppProxyAccess') > 1 ? doSomething : somethingElse
Or, like it was said in one of the comments, use RegEx.

Related

How to check if location.hash has `#access_token=` and if so, do something? [duplicate]

This question already has answers here:
How to check whether a string contains a substring in JavaScript?
(3 answers)
Closed 6 years ago.
Right now, I'm just doing the following for my Auth0 login -
if (location.hash) {
// do something
}
How can I make sure it will only do this when it includes #access_token= ?
Use indexOf like so.
if(location.hash.indexOf("#access_token=" > -1) {
// Do stuff
}
You can learn more on indexOf here.

How to escape # in javascript to retrive object property [duplicate]

This question already has answers here:
JavaScript property access: dot notation vs. brackets?
(17 answers)
Closed 7 years ago.
i have Javascript object as below.
How can i get value for SERIAL#, like i can retrieve *.INST_ID or *.INSTANCE.
how can i escape # and get the value required.
So far i have tried SERIAL#23% but none helped so far.
var t = {"INST_ID":"1","INSTANCE":"xina","SID":"27","SERIAL#":"48810", "PROGRAM":"Perl#app01"}
console.log(kSess.SERIAL%23); gives syntax error
I am parsing variable "t"
This data is coming from java code, so there is nothing much i can do to change SERIAL# to something else
Any idea?
Try to retrieve the value like this...
t["SERIAL#"]; // will return you the value..
Store it somewhere or play with it as you like. :)

Reading Json slash in Javascript [duplicate]

This question already has answers here:
How can I access object properties containing special characters?
(2 answers)
Closed 7 years ago.
I'm reading a JSON file through javascript. I'm having trouble getting today/_text because of the forward slash. I can get today successfully by doing: {{hours.results[0].today}}. How would I get today/_text? I've tried:
today\/_text
today/\_text
today//_text
today\\/_text
{"offset":0,"results":[{"today/_text":"Today:YES","today/_source":"/hours/1","today":"2,3,4"}]}
hours.results[0]["today/_text"] should do the trick!
hours.results[0] returns an object that has that as a key, making that the easiest way to access the property in question.

searching values in array javascript [duplicate]

This question already has answers here:
Determine whether an array contains a value [duplicate]
(18 answers)
Closed 9 years ago.
Is there a built-in function in javascript to do this or this is only the option to go? Please look at the code below:
var arr=[1,3,4,'+','-', or whatever]
function value_check(user_click){
var operators=['+','-','/','*','.']
for (var i=0;i<operators.length;i++){
if (arr[arr.length-1]==operators[i]){var value1='operator found';}
if (user_click==operators[i]){
var value2= value1;alert("consecutive operators"); break;
}
}
}
I think this code achieves what I intend to do but is there a simple and shorter way of doing this. In words, I want to achieve something like this:
if (arr[arr.length-1] && user_click BOTH ARE IN operators array)
alert("consecutive operators)
Yes, there are some options:
JavaScript indexOf()
jQuery.inArray()
arrayName.indexOf() is what you are looking for.

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