-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InAppBrowser.on(‘beforeload’) not working #2819
Comments
ahh sorry not a bug. this feature was pushed 2 months ago (apache/cordova-plugin-inappbrowser#276), and v3.0.0 of cordova-plugin-inappbrowser is 10 months old. still in master branch and not tagged. :(
|
What about version 3.1.0 recently released? |
^ I see we need to wait a bit, but I guess soon apache/cordova-plugin-inappbrowser#500 |
version
|
@danielsogl the issue seems to be unresolved. Can you reopen this? |
Hi @Sroose, I can't confirm this. I'm using beforeload with "get" instead of "yes" (perhaps its wrong in the docs example) and for me it works as expected! I'm using version 3.1.0
|
Hi @JPustkuchen, sure, it can be done this way in Ionic 3. The problem is, in Ionic 4 we can't use addEventListener, because there is new api based on Observer pattern like .on('beforeLoad').subscribe(...) and there is probably no way to can pass any more argument to subscribe handler. |
This is still an issue. I'm trying to start this as a v3 project to get around this issue but even that uses angular and typescript so I can't see to figure it out! Going to try v2 now. Does anyone know how we can utilise the beforeload system? |
Yes, I had this same issue and ended up putting in a fix with PR #3249. Essentially, with that fix you can now call the _beforeAfterLoad method inside your beforeload listener as the callback method:
|
This is excellent news - thanks so much for replying and the fix. I'll check it out. |
Sure thing! I banged my head on this for several days so I hope this helps. They merged my code in back in December, but I'm not sure what version of the npm package contains the fix (whether it's v4 or v5 of Ionic Native Core)... What I ended up doing was keeping a fork of my fix in Github and referencing that fork directly in my
|
This is super helpful - we've been battling with this for months! Thanks so much. |
I have this on my package.json file and still can't use your workaround @mread1208. Do you or anyone here knows what can I do besides using that fork? (cannot use unofficial forks on the company I'm working for). |
I'm able to use this in our implementation and I see the code still exists in the master branch, so things should work: https://github.com/ionic-team/ionic-native/blob/master/src/%40ionic-native/plugins/in-app-browser/index.ts#L184 Do you have an example of how you're implementing? Do you have the "beforeload" option set to "yes" when you're instantiating the InAppBrowser instance? const options: InAppBrowserOptions = {
// Other opts....
beforeload: "yes"
}
const inAppBrowserRef = this.iab.create(url, "_blank", options);
inAppBrowserRef.on("beforeload").subscribe((evt: InAppBrowserEvent) => {
if(evt.url === "something..."){
// Do something
} else {
// Move along
inAppBrowserRef._loadAfterBeforeload(evt.url);
}
}); |
Thanks @mread1208 for the response. During the last weekend I've updated to Ionic Enterprise InAppBrowser and everything worked like a charm. Again, thank you for creating this workaround for the subscribe method! |
I am loading html files using InAppBrowser. I want local links (trusted from domain I control) to open in InAppBrowser, and other links in phone's browser (I want to switch iab's _blank to _system before url opens).
Cordova InAppBrowser implemented some time ago new event called "beforeload" (https://github.com/apache/cordova-plugin-inappbrowser), which does not work with Ionic, and IMHO it is very important for catching navigation before it happens and handling urls that come in from opened InAppBrowser and deciding how to open those urls (eg, override _blank, with _system to open in phones browser instead InAppBrowser etc).
AFAIK It should be activated by passing
beforeload: 'yes'
in window options, and I did all that but event does not fire.I checked @ionic-native/in-app-browser code and does not understand why this wouldn't work.
Any ideas?
ionic info
The text was updated successfully, but these errors were encountered: