Modifier les onglets de l'intérieur WebView
-
28-09-2019 - |
Question
J'ai quelques webviews configuration et avec onglets Appcelerator Titanium, mais il se demande:
Comment puis-je changer d'onglet à partir du WebView html?
ie. J'ai partagé mon application en 4 pages html (à travers 4 onglets). J'ai des liens dans le code html webviews que je voudrais tirer un événement pour les onglets de commutation.
Mes éléments de l'onglet sont configurés comme si dans app.js:
var win1 = Titanium.UI.createWindow();
var tab1 = Titanium.UI.createTab({
icon:'images/tabs/card1.png',
title:'Card 1',
window:win1
});
var webview1 = Titanium.UI.createWebView({url: 'index.html'});
win1.add(webview1);
win1.hideNavBar();
Dans cet exemple, j'ai un a href dans index.html, qui quand on clique dessus, je voudrais passer l'application au 3ème onglet (qui a un autre WebView).
La solution
Vous devez feu et événement dans le fichier HTML et écouter dans votre application
Ti.App.fireEvent Documentation Lien
code dans le fichier HTML
<a href="/" onclick='Ti.App.fireEvent("wvClick",{new_tab:"tab_identifier"}); return
false;'>Switch Tab</a>
code dans le fichier js
Ti.App.addEventListener('wvClick', function(data)
{
Titanium.API.info("--> " + data.new_tab);
});