Looking around I don't expect anybody to be able to help with this.
I'm using phonegap v 3.3.0 and building an android app. Everything works perfectly so long as i don't try to navigate to any url's directly. I believe this might have something to do with the iframe loading internally.
If i use weinre directly I can confirm its with any url change:
window.location.href = "/#home";
If this is run then it will display the white screen along with any links I click internally in the app.
No sooner had I clicked Add question that I realised that the answer was in the question.
Its using an iFrame and after learning from the images that everything needs to be relative it dawned on me.
window.location.href = "/#home";
Will go to the root of the device, which there are no websites.
So you need a reletive path, easiest way when you're navigating using #'s is to use
window.location.href = "#home";
Related
I'm trying to find out answer to my problem, but Google and other sites can't help me.
I'm building mobile website and I need redirect to homepage where browser is reactivated (unlock screen or open from minimalized). Is it possible?
Thanks a lot
Maybe you can do something with window.onunload event
No in short,
There is no specified way to detect a lock screen as such there is nothing in HTML / Javascript.
However you could use PhoneGap and create a mobile application,
I have a class to make events in PhoneGap easy
then you can use Application paused if you still want your application to only work online you can use an AJAX loader to load the content as using PhoneGap dose not hit the Cross-Origin domain policies of JavaScript normally
This i think is the only alternative you can use and it would require quite a bit of work to make your site become a mobile application.
EDIT:
Sorry a bit of Detail. PhoneGap allows you to build mobile applications HTML, CSS & JavaScript and provides some new events into JavaScript to help with mobile applications as well as the ability to call upon the hardware of a phone you can find more out at
http://phonegap.com/
Another Thought:
Thanks to #jeroenk for this idea it just came to me after reading his you might be able to do a little hack fix.
on your page
window.timestamp = Math.round(new Date().getTime()/1000);
setInterval(4000, function(){
var curTime = Math.round(new Date().getTime()/1000);
if(curTime > window.timestamp+5){
// do redirect
}
window.timestamp = Math.round(new Date().getTime()/1000);
});
I'm not 100% but i think Javascript gets halted when the browser on a mobile is not open, so lock screen on minimized so the above will check every 4 seconds that the Javascript has not become out of sink in (allowing for 1 second extra in case there is an application lag it would take some one more than 1 second to get though lock screen unless it was the user using the phone so it was not put down)
As i say this is a thought it might not work.
I have a bunch of links in my app. I added rel='external' target='_blank' to all of them.
In the Ripple emulator, or in a regular desktop browser, this works great. But on my Android (JB 4.2.2) it opens the link in the same window. Hitting "back" takes me back to the app, but everything is screwed and the app does not work as planned (script events do not react), until physically reloaded.
How do I ensure that a link opens in the device's browser? Do I need to use a Cordova plugin?
(I'm using Cordova 2.9.0, jQuery 1.10.1, jQuery Mobile 1.3.1)
This has been really fickle with Cordova/PhoneGap in the last few releases, I believe because of the InAppBrowser work which might be a solution for you.
What is working for us to launch in the external browser is:
window.open("http://myurl.com", '_system');
In our case, we want to find all external links and launch them in Safari/Chrome (and keep internal links in our Angular router). This probably isn't the most elegant solution, but we are doing this right now by capturing input events on the links and taking over the behavior like so:
$(document).on('mousedown','a', function(e) {
e.preventDefault();
var elem = $(this);
var url = elem.attr('href');
if (url.indexOf('http://') !== -1) {
window.open(url, '_system');
}
});
I hope that helps you a bit.
I had issues with Jason Farnsworth's answer still firing the default action after the user returned to the app in iOS. So after a little tweaking of his code I arrived at the following and it behaved as expected.
$(document).on('click', 'a', function (e) {
var elem = $(this);
var url = elem.attr('href');
if (url.indexOf('http://') !== -1) {
e.preventDefault();
window.open(url, '_system');
return false;
}
});
There're a few questions like this, but all of them try to use inappbrowser. I've used the following plugin:
com.byhook.cordova.chromelauncher
Just install it, as always, through cli:
cordova plugin add com.byhook.cordova.chromelauncher
And add the following JavaScript code:
ChromeLauncher.open(url)
This will:
put your app in background mode
open the existing instance of "google chrome for android" browser (according to the code, Google Play is gonna be opened if Chrome browser is not found, but i haven't tested this)
add a new tab to Chrome browser pointing to the desired URL
I've searched ages for the correct answer and managed to fix this another way besides the already given answers.
First of all, older versions of Cordova seem to break when you're using some methods on the newer versions of Android. Updating your Cordova to the latest version will bring some possible migration problems in your current project but is worth the shot of updating. Updated to Cordova 5.0 from 2.8, cost me around half an hour changing the code (just a few fixes required). Rebuilded, deployed and launched succesfully after. The back button made my app crash at the older versions of Cordova. The newer version made it work like a charm with the same line of code. Long story short, update cordova, change a few lines if required and rebuild your beauty.
Hope this will help you from not struggeling days like I did.
You Could just remove
target
attribute
Use only "rel" attribute
I hope it could solve your problem as i face that problem multiple times.
I am developing a project where i intend to open multiple webpages in the same one but not using <iframe>. I have tried in the past using <iframes> but i usually end up with the browser UI locking the webpage, so i have been trying to find alternatives.
I developed a small google chrome extension where instead having opening webpages, i open chrome.windows in the position i want and it works fine, but i wouldn't want any UI around them like the title bar and the buttons like a sort of 'fullscreen' for the dimensions i defined.
chrome.windows.create({ url: app.src, left: wleft, top: wtop, width: wwidth, height: wheight, focused: false, type: "popup" }, function(tab) {
self.windowid = tab.id;
console.log('Window ID is: ' + self.windowid);
//chrome.windows.update(tab.id, { focused: true, state: "maximized" })
});
While looking into chrome extension API i read something about NPAPI and with a little more research i have found about FireBreath. Since i have never did anything with this i have doubts if there is any way or possibility, by developing a plugin npapi/firebreath to do 1 of the following:
When opening a window with chrome extension, somehow remove the UI from it?
With the development of a plugin and having an index.html with 3 <object id="plugin"...> instead of the <iframe>, and inside those 3 object embed on the index, make them open webpages with url that i define and make it change the url after X time that is set on javascript?
This is all assumptions, idk if i am saying anything stupid regarding the possibility to do this with npapi or if i should look somewhere else.
Thanks in advance.
Basically the answer is no, you can't do any of that.
To be more accurate, however, you can do #2 but it's a huge amount of work and may not work how you expect. The only way to load an html page inside an npapi plugin is to actually embed a web browser of some sort into that plugin; FireBreath has an undocumented library called WebView that will do this for you, but it uses the IE engine on windows and on Mac it uses a lot of hacks to make it work which end up only working correctly in certain cases.
Your #1 can't be done in any consistent or reliable; npapi plugins know nothing about the browser itself, only the page. It might be possible using windows APIs to essentially hack into the browser window and change things but it would be very fragile and implementation specific to that version of chrome; if something changed later it'd just break.
I am currently using the following JS code to trigger a file download without leaving the page I'm on:
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
iframe.src = "/somefile.zip";
It works well pretty much everywhere I tested except on both the stock Android browser and Dolphin, where the download doesn't start at all. So far so good, after some research this hidden iframe trick happens to be known not to work on the Android browser.
But I tried several other methods to trigger the download on the Android browser, including window.open() (not reliable because popup blocking is enabled by default), or <a target="_blank"> with a simulated click() (which from a popup blocker perspective amounts to window.open() and gets blocked), or document.location = ... which downloads the file but breaks my app.
The problem with the latter document.location = ... is that this is a Comet application (server-push / long polling) so I really can't leave the page I'm currently on (and "leaving" includes changing document.location even for a file download, even if apparently the browser stays on the current page) otherwise the long polling connection is stopped and the updates stop, the app breaks. This obviously also applies when clicking normal links, either manually or simulated.
So in order not to break my app I really need to trigger a file download without leaving the page I'm on. Unfortunately I didn't find any viable solution that also works on the stock Android browser.
Any ideas?
Thanks for reading me.
Try using the anchor and simulated click without using a target=blank
I say this because I had a similar download consisting of an iframe and a simple link as fallback. The iframe worked on everything but the android, but the simple link would download successfully without leaving the page.
I have problem with Facebook Comments plugin. Is it event possible to embed it on UIWebView in iOS application? I don't mean using loadUrl method ... but using loadHTMLstring ( I want it only localy on my application, without using any messy obj-c code if it's possible ). I'm using HTML5 code for it, but it's not working on simulator ...
Am I doing anything wrong?
I've read similar topics, but haven't found any solution, that might help me.
Thank's in advance for any help!
well, i found some workaround for this problem. what i needed is to load local html page with comments plugin embedded. this html page is stored in resources of project. so the code for me was something like that:
[reviewsView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:#"comments" withExtension:#"html"]]];
where reviewsView is a UIWebView element. however, it didn't work correctly in the end - comments had loaded, but facebook "loading progress bar" was still animating and for some reason login button was unclickable. so i just returned to the idea with remote html comments page.