framework7

Open full view…

How to check if page exists?

energysmithe
Mon, 11 Aug 2014 16:57:23 GMT

I am using the example dynamically created content and it is working great, but since the user is launching it from a tab-link I need to detect if the page has already been opened, otherwise it creates a new page each time they click on the link. Is there a way to detect via javascript if the dynamic page/content exists already? (I am setting the data-page and page callback events are firing correctly...) Or is there a more elegant way of handling this? Great job with Framework7, it is amazing!

Vladimir Kharlampidi
Mon, 11 Aug 2014 16:58:48 GMT

If you mean to check is it presented in DOM, you can do it simply like: --- if ($$('.page[data-page="dynamicpage"]').length > 0) { console.log('page exist'); }

Vladimir Kharlampidi
Mon, 11 Aug 2014 16:59:09 GMT

Just change to appropriate data-page attribute

energysmithe
Mon, 11 Aug 2014 21:30:38 GMT

Vladimir, thank you that worked great! I found that immediately after running createContentPage() the event does not evaluate, so I catch it on the second click and am just closing the page instead to create a toggle effect. Very nice! --- var pageExistsInDom = false; if ($$('.page[data-page="dynamicPage"]').length > 0) { pageExistsInDom = true; } if (pageExistsInDom == false) { createContentPage(); } else { mainView.goBack(); } ---