I am loading an external URL in ionic2 InAppBrowser. I want to add a floating button above the webview for capturing the screenshot of the webpage which is loaded in the InAppBrowser. Is there any way to do this?
Asked
Active
Viewed 596 times
1 Answers
0
The problem with doing that with InAppBrowser is that it sets itself as top z-index so no matter what you add it will be under it.
Here is a workaround using iframe
and FabButtons
(or Floating Action Buttons
: fab docs)
For example:
.html
<ion-content>
<iframe no-margin name="myName" [src]=cleanUrl></iframe>
</ion-content>
<ion-fab left top>
<button ion-fab color="danger" (click)="buttonClick()">
<ion-icon name="arrow-dropleft"></ion-icon>
</button>
</ion-fab>
.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { DomSanitizer } from '@angular/platform-browser';
@IonicPage()
@Component({
selector: '<SELECTOR HERE>',
templateUrl: '<PAGE NAME HERE>.html',
})
export class MyPage {
url: string;
cleanUrl: any;
constructor(
public navCtrl: NavController,
public navParams: NavParams,
private domSanitizer: DomSanitizer
) {
this.url = 'http://www.example.com/';
}
ionViewWillEnter() {
this.cleanUrl = this.sanatizeUrl(this.url);
}
sanatizeUrl(url: string): any{
return this.domSanitizer.bypassSecurityTrustResourceUrl(url);
}
buttonClick() {
console.log('buttonClick');
}
}
Please note the use of DomSanitizer that will be necessary if you get errors displaying the url.

Tadija Bagarić
- 2,495
- 2
- 31
- 48
-
how to place this fab button in **InAppBrowser** ? – Abhishek Nov 09 '17 at 06:53
-
Not sure if this is possible with `InAppBrowser`, but here is a workaround using `iframe` – Tadija Bagarić Nov 10 '17 at 09:03
-
Thanks for your response. i am trying to open a https site and getting the error "Load denied by X-Frame-Options:". – Abhishek Nov 13 '17 at 11:16
-
Some websites have a server setting that will not allow other websites to "frame" their content. This is mainly to protect their copyrights and direct traffic to their websites only - Unfortunately, there is really nothing you can do about it if you want to frame the website. For more info: https://stackoverflow.com/questions/38699221/load-denied-by-x-frame-options-does-not-permit-framing – Tadija Bagarić Nov 13 '17 at 11:23