Cordova: load links in webview - javascript

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

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?

Google chrome does not show PDF files in iframe

I use Pdf.js, I get base64 file from web service (this.attachmentSource), and when I want to add var iframe = "<iframe width=800 height=550 src='" + this.attachmentSource + "' > </iframe>",For some pdfs in google chrome I get iframe empty, but in Mozila everything work fine, who can explain this mystery?
I tracked down the issue
The iframe is being block by chrome detecting insecure content and blocking the iframe from loading. this only occurs when using Chrome, IE Firefox, Safari on PC work fine.
Safari and Chrome also work fine on the iPad. It appears Chrome on PC has a different set of rules and blocks the content. Selecting the shield in the URL title bar allows the content to be displayed. Pressing Ctrl shift J gives some information about what content is being blocked.
wouldn't it be nice if all the browser followed the one set of rules
I happened to notice: server Response Header:
x-frame-options: DENY
The DENY option is the most secure, preventing any use of the current page in a frame. More commonly, SAMEORIGIN is used.
I was using AWS CloudFront with a Lambda#Edge function already, so I found a solution here: Configuring X-Frame-Options Response Header on AWS CloudFront and S3
If you are using a different server stack, you will have to adjust your server response headers accordingly.
iFrame doesn't support most of the things. For ex: if you have graphs in your application it won't be displayed.Use embed or object instead.
<object data="{{srcUrlTrusted}}" width="100%" height="800">
<embed ng-src="{{srcUrlTrusted}}" width="100%" height="800"> </embed>
</object>
I was having the same issue when trying to embed a PDF. I tried both an <iframe> and <embed> approach, but they still wouldn't open in Chrome.
The solution for me was opening the PDF in Adobe Acrobat and under the "Protect" tab, select "Remove Hidden Information".
I didn't create this PDF, so I am not sure which policy, etc was causing the issue.
Hope this helps!

prevent opening safari in cordova webview links

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?

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://*/*" />

Is there some default popup for appstore download on itunes when webapp is viewed in mobile safari?

I've seen the same popup across multiple websites when viewing a site in safari on iphone. For example viewing wunderlist.com and vsco.co yield the same popup when viewed on iphone on safari prompting the user to download the app. Is this something baked into safari or is this a plugin? Maybe they are built from scratch but it seems like several sites are using the same popup....
Yes, there is and it's based on a meta tag.
<meta name="apple-itunes-app" content="app-id=myAppStoreID">
You can also provide other (optional) parameters for example to generate better links for the already installed application (you can link to specific content inside the app):
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
See more information here:
https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html

Categories

Resources