So you have two things to accomplish:
1st - Browser Detecttion
Browser detection via javascript is tricky thing to do, I recommend for you to take a look at this post to understand it.
You have to catch Android and iPhone browsers and both of them have the "mobile" string in theirs user agent (like all decent mobile browsers), so you can do it with a function like:
function isMobile() {
return (/mobile/i).test(window.navigator.userAgent);
}
This function will return true, when in a mobile browser.
Take a look at this question for alternative approaches.
2nd - Cookie Access
The cookie "API" is an even worse interface. To deal with it you have to write your key=value data to document.cookie (read the MDN's documentation).
So, if you want to store on cookies the user preference, you can do something like:
document.cookie = "skip_message=1"
As I said, the cookie API interface can be very tricky sometimes so you should use a 3rd party library to read an write cookies. The little framework in the MDN documentation is a good one.
Your target browsers have more advanced features, so if you don't need to suport older browser I would recommend you to use localStorage