External URL in Phonegap - android

I want to open a link say www.google.com in Phonegap Android... I've tried lot of things but I'm not able to open any link.
<access origin="http://google.com" /> is already added to config.xml.
navigator.app.loadUrl('http://google.com'); is giving an error.
$('#pageID').load('http://google.com',function(){
$('#pageID').trigger('create');
});
is loading the page but the images are not displayed, which is required in my case.
Can anyone explain how to actually open a link in Phonegap.

Well it seems its not possible ..... but I found that we can do it other way round.
We know this works :-
<a data-role="none" id="someID" href="#" target="_blank">
So we can write jQuery as :-
$('#idAnchorTag').attr('href','some URL');
So the complete code is :- (Assuming that click was made on an image)
<a data-role="none" id="idAnchorTag" href="#" target="_blank">
<img id="idIMG" src="some IMAGE">
</a>
And the JS :-
$(function() {
$("#idIMG").click(function(){
$('#idAnchorTag').attr('href','some URL');
});
});

try
$('#pageID').onClick(function(){
document.location.href="http://google.com";
})

Related

<a> tag download attribute not working for mobile

I have this anchor tag as below:
<a className="badge-link" href="./download/myapp-v1.1.0.apk" download="myapp-v1.1.0.apk">
<img src="img/download-apk.png" alt=""/>
</a>
Just want to clarify that the apk file & website is hosted at a server and I'm downloading the file from there.
The download works on PC but on mobile it gets stuck at downloading status forever.
It doesn't show download progress at all.
I've tried closing the download manager & clearing its cache for android but I still get the same result.
How do I make this download work on android/iphone?
Or is there any other alternatives?
Issue seems to be with the path u specified in the href. Try giving absolete path like
"http://somedomain.com/somefolder/somefile"
<a className="badge-link" onclick="startDownload('http://somedomain.com/somefolder/somefile')" download="myapp-v1.1.0.apk"> <img src="img/download-apk.png" alt=""/> </a>
//Js to open in the same tab
<script>function startDownload(url) { window.location.href = url; }
</script>
On the HTTP Response where you are returning the file, ensure the content disposition header looks like:
Content-Disposition: attachment; filename=filename.extesion;
Check this for more about content wiki-disposition
Just to test give some third party link first later try with yours
I think in your pc you have that apk file on the project folder, but in your mobile and also in your project folder that apk file is missing.
And also you can try this code
<a className="badge-link" href="download/myapp-v1.1.0.apk" download>
<img src="img/download-apk.png" alt=""/>
</a>
Try this
<a className="badge-link" href="http://somedomain.com/download/myapp-v1.1.0.apk" download="myapp-v1.1.0.apk">
<img src="img/download-apk.png" alt=""/>
</a>
I think it's because when you're testing on PC, you have the apk inside your project directory.
But you don't have it on mobile.

Issue with cordova plugin to set wallpaper with auto link

I'm using cordova-plugin-wallpaper which works fine if i hardcode image like this.
window.plugins.wallpaper.setImage("images/1462204239933.jpg");
but if i try to get image link with jquery from active slide, it won't set wallpaper with android app. This is what i tried.
var picture = $$(".swiper-slide-active").find(".pic").attr('src');
window.plugins.wallpaper.setImage('"'+picture+'"');
I checked console.log and it's getting image src fine for each slide. Any suggestion how to work around this? Thanks
There was strings around variable ('"'+picture+'"') which were causing the issue. Removing that fixed the issue. Thanks to "flyingP0tat0" for pointing this on github issue.
Here is the full code if anyone need.
HTML
<div class="page-content">
<button class="setwp floating-button"><i class="icon icon-plus"></i></button>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide"><img src="images/001.jpg" rel="1"></div>
<div class="swiper-slide"><img src="images/002.jpg" rel="2"></div>
<div class="swiper-slide"><img src="images/003.jpg" rel="3"></div>
</div>
</div>
</div>
JS
function wp() {
var wppic = $$(".swiper-slide-active").find("img").attr('src');
window.plugins.wallpaper.setImage(wppic);
}
function wpalert() {
alert('Wallpaper is set');
}
$$('.setwp').on('click', function (e) {
wp(); wpalert();
});

Ionic InAppBrowser not working

how to open external link from a ng-repeat.
I already tried different combinations but not external window opens.
when I put just one link it works but when I use expressions {{event.lermais}} to open links does not work.
this is my code:
<ion-item class="item-text-wrap item-icon-right" ng-repeat="event in events.data.results">
<img ng-src="{{ event.imagens }}">
<i class="icon ion-chevron-right icon-accessory"></i>
</ion-item>
I'm using Android
HTML
ng-click ="openLink(event.lermais)"
Controller
$scope.openLink= function(url){
window.open(url, "_blank", "location=yes");
}
Its a cakewalk.
you can do that bu using following eg-
<a href="{{menu.url}}" onclick="window.open(this.href,'_self');">
{{menu.title}}
</a>
this might work for you.

Android Browser with Phonegap and jQuery mobile

I have a strange problem. I'm developing an Android app with Phonegap and jQuery Mobile.
The issue is this. I have two pages, pageA and pageB... In page A for example I have this:
<div id="Menu" data-role="navbar">
<a href="pageB.htm" onclick="DoSomeThink()" >Page</a></li>
</div><!-- /navbar -->
In PageB I have a script loaded in a JS file. When the page is loaded there is this event:
$('.ClassPageB').live('pageshow', function(event, ui) {
\\Some code here
});
If I deploy this on Android phones everything is ok... But if I deploy on tablets the
live.(pageshow event...) is not performed.
The only way I could resolve the problem is to put in a tag target="_self" in the link like this:
<a href="pageB.htm" onclick="DoSomeThink()" target="_self" >Page</a></li>
But if I use this I loose transition effects of JQmobile...
Any ideas?
Try loading the JS file containing:
$('.ClassPageB').live('pageshow', function(event, ui) {
\\Some code here
});
in BOTH PageA and PageB.
Let me know if this works for you.

Android Webview href not working

I am using the following code in my Webview along with Jquery Mobile, This works fine in the emulator (2.2 ) and on my Nexus one but some users are complaining that when they click on a link they get an error message "Problem with File: Requested file not found". One user reported that she was using Samsung Fascinate with "2.2.1" . This seems to have started when I upgraded jquery mobile 1.0b2 , I have tried the latest 1.0rc but still have the same issue
Any Insights on what might be happening ?
In my Activity
engine.loadUrl("file:///android_asset/book2/www/newindex.html");
In the html ( I have also tried data-ajax="false" )
<link rel="stylesheet" href="jquery/jquery.mobile-1.0rc1.min.css" />
<script type="text/javascript" src="jquery/jquery.mobile-1.0rc1.min.js"></script>
<div data-role="page" id="jqm-home">
<div data-role="content" data-theme="e">
<div class="content-primary">
<nav>
<ul data-role="listview" data-inset="true" data-theme="e" data-dividertheme="d" >
<li data-role="list-divider">Cognitive</li>
<li><a rel="external" href="./cogn/simon2.html">
<img src="cogn/simon.jpg" />
<h3>Simon says</h3>
<p>Memory</p>
</a></li>
From what I know about URL loading, if you are loading a local file, which is what it looks like here, that file needs to be in the same directory as the file its linking from. Because the file is local on your computer, your device and emulator should work fine. for someone else who downloads the app and tries to use the Webview functionality, that source file would need to be stored in their phone and in the appropriate directory...hope that helps.

Categories

Resources