I made an app that is just a webview showing a website, at a certain point in my website I have a button that prints a div via javascript, as it is it doesn't work, how can I make it possible?
my js code:
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
Related
I want to load a webpage on android Webview. Is there a way to override some CSS component of the web page in my android webView?
Upload your customized css somewhere. You can apply your new css using Javascript. You can inject following javascript after the WebView is finished loading:
var link = document.createElement("link");
link.href = "http://example.com/mystyle.css";
link.type = "text/css";
link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(link);
So your final Java code will look something like this:
String jsToInject = "var link=document.createElement('link');link.href='http://example.com/mystyle.css';link.type ='text/css'; link.rel ='stylesheet';document.getElementsByTagName('head')[0].appendChild(link);"
myWebView.loadUrl("javascript:" + jsToInject);
Hey everyone so I was wondering if there is a easy method of doing this or if it can even be done without an ANE Native Extension. I picked up some code from around here and in my Flash CS6 Android AIR Application using AS3 I created two buttons on the stage one for Facebook and the other for Twitter. When the user clicks on the buttons they are redirected to the URL's and are able to post the link that I give in the vars like so:
//Share button event listener
menuEnd.share_Facebook.addEventListener(MouseEvent.CLICK, shareFacebook);
menuEnd.share_Twitter.addEventListener(MouseEvent.CLICK, shareTwitter);
private function shareTwitter(e:MouseEvent):void
{
var varsShare:URLVariables = new URLVariables();
varsShare.u = 'https://play.google.com/store/apps/details?id=air.bunnyRunner';
varsShare.t = 'Jumpy Bunny';
var urlTwitterShare:URLRequest = new URLRequest('http://twitter.com/home?status= Jumpy Bunny by Fitchett Productions: ');
urlTwitterShare.data = varsShare;
urlTwitterShare.method = URLRequestMethod.GET;
navigateToURL(urlTwitterShare, '_blank');
}
private function shareFacebook(evt:MouseEvent):void
{
var varsShare:URLVariables = new URLVariables();
varsShare.u = 'https://play.google.com/store/apps/details?id=air.bunnyRunner';
varsShare.t = 'Jumpy Bunny';
var urlFacebookShare:URLRequest = new URLRequest('http://m.facebook.com/sharer.php');
urlFacebookShare.data = varsShare;
urlFacebookShare.method = URLRequestMethod.GET;
navigateToURL(urlFacebookShare, '_blank');
}
So now I was wondering since I have sharedObject data in my game is there anyway to get that shared.data and display it on facebook when the user clicks the button it shares the data to facebook and they can post their highscore?
Thanks guys any help is appreciated.
I have a html page which is used in a android application . From this page i need to post data to server and response is an attachment which needs to be downloaded. I used the hidden iframe hack for this purpose. But unfortunately its failing. Can anyone explain the root cause?
function download(){
var iframe = document.createElement("iframe");
//iframe.src = "http://localhost:9080/HttpOptions/MultiPartServlet";
iframe.style.display = "none";
iframe.id = "myframe";
document.body.appendChild(iframe);
var doc = document.getElementById("myframe").contentWindow.document;
var form = doc.createElement("form");
form.setAttribute("name", "theForm"); // give form a name
form.setAttribute("id", "theForm"); // give form a name
form.setAttribute("action", "http://localhost:9080/HttpOptions/MultiPartServlet"); // give form an action
form.setAttribute("method", "post"); // give form a method
var par1 = doc.createElement("input");
par1.setAttribute("name", "theSubmit"); // give input a name
par1.setAttribute("type", "submit"); // make it a submit button
par1.setAttribute("value", "Submit"); // give input a value
var par2 = doc.createElement("input");
par2.setAttribute("name", "name"); // give input a name
par2.setAttribute("type", "text"); // make it a submit button
par2.setAttribute("value", "deepak"); // give input a value
form.appendChild(par1);
form.appendChild(par2);
doc.body.appendChild(form);
var myframe = document.getElementById('myframe');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
form.submit();
}
Set the document.domain to same value in both parent page and framed page.
Example:
<script type="text/javascript">
document.domain = 'example.com';
</script>
Put this in both parent page and framed page, and the problem will be gone.
I have a really weird scenario that I'm stuck on. I have a ASP.Net MVC 4 app where I'm authenticating a user and creating an authCookie and adding it to the response's cookies then redirecting them to the target page:
if (ModelState.IsValid)
{
var userAuthenticated = UserInfo.AuthenticateUser(model.UserName, model.Password);
if (userAuthenticated)
{
var userInfo = UserInfo.FindByUserName(model.UserName);
//SERIALIZE AUTHENTICATED USER
var serializer = new JavaScriptSerializer();
var serializedUser = serializer.Serialize(userInfo);
var ticket = new FormsAuthenticationTicket(1, model.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), false, serializedUser);
var hash = FormsAuthentication.Encrypt(ticket);
var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash) {Expires = ticket.Expiration};
Response.Cookies.Add(authCookie);
if (Url.IsLocalUrl(model.ReturnUrl) && model.ReturnUrl.Length > 1 && model.ReturnUrl.StartsWith("/") && !model.ReturnUrl.StartsWith("//") && !model.ReturnUrl.StartsWith("/\\"))
{
return Redirect(model.ReturnUrl);
}
var url = Url.Action("Index", "Course");
return Redirect(url);
}
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
This is working just fine in all browsers. I can login and access the secure pages in my app.
My client is requesting an android version of this app. So, I'm trying to figure out how to convert this app into an APK file. My first attempt is to create a simple index.html page with an iframe that targets the application. This works just fine in Firefox and IE 9. However, when accessing the index.html page that contains the iframe that points to the app via Chrome, I get past the login code above and the user gets redirected to the secure controller, but the secure controller has a custom attribute to make sure the user is authenticated:
public class RequiresAuthenticationAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.HttpContext.User.Identity.IsAuthenticated) return;
if (filterContext.HttpContext.Request.Url == null) return;
var returnUrl = filterContext.HttpContext.Request.Url.AbsolutePath;
if (!filterContext.HttpContext.Request.Browser.IsMobileDevice)
{
filterContext.HttpContext.Response.Redirect(FormsAuthentication.LoginUrl + string.Format("?ReturnUrl={0}", returnUrl), true);
}
else
{
filterContext.HttpContext.Response.Redirect("/Home/Home", true);
}
}
}
My app is failing on: filterContext.HttpContext.User.Identity.IsAuthenticated. IsAuthenticated is always false, even though the user was authenticated in the code above.
Keep in mind this only happens when accessing the app via iframe in Chrome. If I access the app directly instead of via iframe, then everything works just fine.
Any ideas?
UPDATE:
My controller extends SecureController. In the constructor of SecureController I have the code that deserializes the user:
public SecureController()
{
var context = new HttpContextWrapper(System.Web.HttpContext.Current);
if (context.Request.Cookies[FormsAuthentication.FormsCookieName] != null)
{
var serializer = new JavaScriptSerializer();
var cookie = context.Request.Cookies[FormsAuthentication.FormsCookieName].Value;
var ticket = FormsAuthentication.Decrypt(cookie);
CurrentUser = serializer.Deserialize<UserInfo>(ticket.UserData);
}
else
{
CurrentUser = new UserInfo();
}
//if ajax request and session has expired, then force re-login
if (context.Request.IsAjaxRequest() && context.Request.IsAuthenticated == false)
{
context.Response.Clear();
context.Response.StatusCode = 401;
context.Response.Flush();
}
}
First, you should be deriving from AuthorizeAttribute, not an ActionFilterAttribute. Authorization attributes execute before the method is even called at a higher level of the pipeline, while ActionFilters execute much further down, and other attributes can execute before yours.
Secondly, you aren't showing the code you use to decrypt the ticket and set the IPrincipal and IIdentity. Since that's where the problem is, it's odd that you didn't include it.
Everything is working when open it with Opera mobile and Firefox, but when I open it with Android browser, the function not working. How to fix it?
$(document).ready(function(){
var price = document.getElementsByClassName('harga')[0];
var tax = document.getElementsByClassName('dp_per')[0];
var taxAmount = document.getElementsByClassName('dp')[0];
tax.onblur = function() {
taxAmount.value = parseFloat(price.value) * parseFloat(tax.value) / 100;
}
})(jQuery);
Here is what I've made:
http://jsfiddle.net/mYEUP/