최근 검색
최근 검색 없음
Javascript Functions in Apps
2022년 10월 18일에 게시됨
Hello All,
I am writing an app but can't get/set cookies for use in the app, nor can I do 'are you sure?' prompts.
I think this may be due to something preventing them in ZenDesk, and is probably expected behaviour.
But is there a way these kinds of function can be achieved?
Thanks,
SGL.
0
7
댓글 7개
SGL
I'm going to close this post as I am now able to save to localStorage, create modals and send messages between them.
I do have an additional issue with modals, but I will create a separate post for it.
Thanks,
SGL
0
Eric Nelson
You'll want to reference this article on messaging between locations.
Thanks!
0
SGL
Hi Eric,
Thanks for the advice. I have implemented localStorage and that works fine.
I can also create modals, but I'm not sure how the main code can interact with the modal e.g. how does the modal return a 'yes' or 'no' response, and how to put a button/listener on the modal. Can you point me in the right direction?
Thanks,
SGL.
0
Eric Nelson
Apologies I missed your earlier messages. Thanks for the code snippets, this helped clarify things for me.
1. The confirm function won't work as you anticipate it as the Zendesk apps function in an iframed environment. You can get around this though by implementing your own prompt using a modal.
2. Similarly as the app is in it's own document from being iframed you'd want to implement your cookie using localStorage.
1
SGL
Hi Eric,
Have you time to consider my issue?
Thanks,
SGL.
0
SGL
Hi Eric,
Thanks for the reply.
For the 'are you sure?' popup issue, I have code like this...
-----------------------------------------------------------------
const exportButton = document.getElementById('export');
exportButton.addEventListener('click', function(e) {
console.log('button was clicked');
var proceed = confirm("Are you sure you want to download this file?");
if (proceed) {
downloadCSV();
} else {
//don't proceed
}
});
-----------------------------------------------------------------
But this gives an error in the console when clicked...
Ignored call to 'confirm()'. The document is sandboxed, and the 'allow-modals' keyword is not set.
-----------------------------------------------------------------
For the cookies I have this code...
-----------------------------------------------------------------
function setCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
-----------------------------------------------------------------
If I do this:
-----------------------------------------------------------------
setCookie('test','hello',7)
testCookie = getCookie('test');
console.log(testCookie);
-----------------------------------------------------------------
Then it returns a null value. The document.cookie value looks like this...
ASPSESSIONIDSSDBCBTA=JKONNMNDBBKJPGMPPOKNGEBP
0
Eric Nelson
Both of these things aren't restricted to do within a zendesk app. Can you provide some code snippets of how you're trying to accomplish this?
Thanks!
0
댓글을 남기려면 로그인하세요.