Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (evaljs)
Viewing all articles
Browse latest Browse all 83

Trouble setting webview cookie with webview.evalJS function and beforeload event

$
0
0

I've been stuck on this problem for the last few days and can't seem to work out what the problem might be. I'm trying to set a cookie before loading a page in a webview on android. Code looks like this:

var container = Ti.UI.createView();
win.add(container);
 
var webview = Ti.UI.createWebView({url:SITE_PATH+'user/'+user.uid+'/edit', height:Ti.UI.FILL, width:Ti.UI.FILL}); 
var cookie = Titanium.App.Properties.getString("cookie");
webview.addEventListener('beforeload', function(e)
{   
    Titanium.API.info('calling beforeload');
    webview.evalJS('document.cookie="'+cookie+'";'); 
});
webview.addEventListener('load', function(e)
{   
    Titanium.API.info('cookie is:'+webview.evalJS("document.cookie"));
});
 
container.add(webview);
win.open({modal:true});
 
var refresh = Titanium.UI.createButton();
refresh.addEventListener('click', function()
{   
    webview.reload();
});
The weird thing is after hitting the reload button a few times the cookie kicks in and everything is ok, just can't get it to work first time ever. I am using Drupal as a back end and all I can think of is that it is possibly causing some sort of issue? Why does the beforeload function not set the cookie properly?

Any help appreciated.


Viewing all articles
Browse latest Browse all 83

Trending Articles