prevent opening safari in cordova webview links - javascript

In my cordova app I just open an external website as the content src:
<content src="http://example.com" />
When linking inside my website with normal links:
<a href='/internal.html' />
it opens external safari browser and not staying inside the app.
I've managed to achieve staying inside the app by using this code:
<a href='javascript:void(0)' onclick='window.open("/internal.html","_self")'></a>
Is there a way to stay HTML native without javascript and link inside the app?

Related

How can i fetch youtube webpage source code using android studio

i am creating an app to read tags form youtube videos but when i try to download web page using AsyncTask it showing an error like
</script>
05-21 01:18:37.829 12067-12067/com.improfessional.j.tagfetcher I/System.out: <noscript>
05-21 01:18:37.829 12067-12067/com.improfessional.j.tagfetcher I/System.out: براہ کرم اپنے براؤزر پر جاوا اسکرپٹ فعال کریں۔
05-21 01:18:37.829 12067-12067/com.improfessional.j.tagfetcher I/System.out: </noscript>
05-21 01:18:37.829 12067-12067/com.improfessional.j.tagfetcher I/System.out: </html>
which means to enable java script...
And is there a way to download webpage code faster cause AsyncTask is taking noticeable long time.
Thank-you
Problem is related with youtube web site. Pages can't be downloaded without browser (javascript). May be you need to use webview ( hidden ) to load page
Check How do I get the web page contents from a WebView?

Cordova: load links in webview

I load an external website (with different HTML files) in an iframe in a cordova webview on iOS.
Now when i click a normal link in the iframe (points to another html page), the Safari browser opens with that page. But i want it to change the location inside the iframe.
The only way it works is to overwrite the click action
$('a').click(function(event){
event.preventDefault();
window.location.replace($(this).attr('href'));
}
But that is not nice. Is there any way to prevent cordova to open links in the external safari app (perhaps in config.xml)?
Take a look at the cordova-plugin-whitelist plugin:
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/
This plugin implements a whitelist policy for navigating the application webview on Cordova 4.0
You may want to add to the config.xml something like:
<allow-navigation href="http://example.com/*" />
.... for each trusted domain, where example.com is the trusted domain
Instead of window.location.replace, try using window.open with _self as the name.
window.open($(this).attr('href'), "_self");
https://cordova.apache.org/docs/en/2.6.0/cordova/inappbrowser/window.open.html

Unable to load the PDF from local in chrome mobile version view

I'm working on a project which needs to open a PDF from a local path in a dialog box. I am able to open the PDF from a normal chrome browser but I am not able to open the same PDF from chrome mobile version view(inspect element-console). I have seen so many links suggested to open from google drive, but it cannot open the PDF if the internet connection is not available. How can I achieve this without google drive process. Please help me out from this problem, thanks in advance. The code which I written so far.
Note: I am restricted from using jQuery in this project, only JavaScript is allowed.
function pdf(objFRM, local_src){
document.getElementById('dialog').style.display = 'block';
document.getElementById(objFRM).style.display = 'block';
document.getElementById(objFRM).src = local_src;
console.log(document.getElementById(objFRM).src);
}
<a onclick="pdf('iFrame', 'assets/pdf/sample.pdf')"><button class="gray-button">Manual</button></a>
<div id="dialog" style="display:none;">
<div class="modals">
<iframe id="iFrame" type="application/pdf"></iframe>
</div>
</div>
I have heard about an issue with Chrome where PDFs won't display/render, but work just fine in other browsers. Try using a different browser to make sure the issue isn't with Chrome itself.
If this is a local website,
assets/pdf/sample.pdf
would only work if your code files are in the folder with assets.
Afaik there is no built in PDF-Viewer in the mobile version of chrome. So you need to install a separate PDF-Viewer App to display PDFs. What you could do is offer the mobile users a link, where they could "download" the file to open it in an external viewer:
<a id='myPDF'>Get Me</a>
document.getElementById(objFRM).href = local_src;
Usage of 'iframe' is discouraged these days for security reasons. Although for resources, in the same origin it won't be a problem. But I would suggest using embed or link tag for it. To open/pop-up a pdf, you can also use target attribute from 'anchor' tag.
<object name="frame_1" data="/assets/template/test_pdf.pdf" type="text/pdf" width="600" height="500">
<embed src="/assets/template/test_pdf.pdf" id="embed_pdf"></embed>
</object>
<link rel="import" name="frame_2" href="/assets/template/test_pdf.pdf">
<a target="frame_1" href="assets/template/test_pdf2.pdf" class="btn btn-raised btn-info">Load PDF</a>
<a target="frame_2" href="assets/template/test_pdf3.pdf" class="btn btn-raised btn-info">Load PDF</a>

iOs 9 WhatsApp share from within iframe in safari isn't working

I have a web app supplied through iframe for other websites to embed.
In it, there's a share button for Whatsapp and it doesn't seem to work (the button isn't responding) in safari in devices with iOs 9+.
When testing the application in a non-iframe environment, the share button seems to work.
The code for the share link:
<div class="whatsapp sharer">
<a ng-href="{{'whatsapp://send?text=' + message}}" target="_blank" data-action="share/whatsapp/share"></a>
</div>
It seems to be a problem because of the security changes made in iOs9, but is there any way to bypass this?

iOS Phonegap webpage links embedded in iframe open system browser instead of in iframe

When embedding a webpage via an iframe in phonegap, any links on that webpage will open the system browser instead of the iframe. This only occurs on iOS and only on the compiled version. Android and the phonegap app for iOS work as intended as webpage links open inside the iframe.
Config.xml preferences like 'stay-in-webview' and 'Cordova.plist' appear to be deprecated out and no longer work. Also 'ChildBrowser' preference is blackberry only. Finally the 'inAppBrowser' plugin has the same issue. It loads the webpage just fine internally but any links will trigger Safari to open.
The issue can be re-created by simply starting a new phonegap application, embedding an iframe, and then building for iOS / exporting with xcode.
Any help would be much appreciated!
Solution:
At least in the latest phonegap (6.0 at the moment), having the below tags enabled for compiled iOS causes this issue. My best guess is that allowing these intents inadvertently tells iOS to open any / all embedded links in Safari.
I simply removed the below tags and everything is loading properly in the iframe
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />

Categories

Resources