framework7

Open full view…

How to change the loaded ajax pages before rendering

emanage
Mon, 13 Nov 2017 16:55:39 GMT

I want to replace some text of the loaded ajax pages before rendering for multi language purpose I am using the following function html file ======== ......... <div>{green}</div> ....... ....... <script>translate(0)</script> dictionary js file ============ phrase={ 'languages': ['AR','EN','FR'], 'gray': ['رمادي','Gray',''], 'green': ['أخضر','Green',''], 'name': ['الاسم','Name',''], } function translate(language){ var re = /\{\w+\}/g; var s = document.body.innerHTML; var m=''; do { m = re.exec(s); if (m) { m=m.toString().replace('{',''); m=m.replace('}',''); s=s.replace('{'+m+'}',phrase[m][language]); } } while (m); document.body.innerHTML=s; }

oleglevin
Tue, 14 Nov 2017 11:55:30 GMT

Think you should do this in app.js before initializing page

emanage
Wed, 15 Nov 2017 13:10:17 GMT

but the value "document.body.innerHTML" will be empty before initializing page. it works fine fore the loaded index.html page but how to get it working after clicking a new link like about.html for example. I want to catch the page innerHTML and change it before loading.