How to cache page after clicking using phonegap? - html

I begin to develop mobile app using PhoneGap. First I make 2 .html files named index.html and place.html
In index.html I use $.get() method to get json data from web service and then show on HTML tag.
When user click link from index.html page it going to place.html. In place.html I put back button like
Back
for back to index.html page.
A problem is when I click back button to index.html page it run $.get() method when page is loaded.
How to cache index.html page? When I clicking back button, it use same data from the first time.
Thanks!

Have you tried jQuery mobile?
You don't have to actually incorporate the entire library, but only utilize the
<div class="home-page" data-role="page" data-dom-cache="true" >
attributes on the Home page container. Another thing to note is that all your pages need the data-role="page" attribute for jQM to work.
By default, jQM has disabled caching, you can enable it in JavaScript as follows
$.mobile.page.prototype.options.domCache = true;
Reference: jQM Documentation on caching pages

Related

How to open page by it link as one html component inside my htlm page without leaving it?

in html file i can make
<h1> the following page is google page </h1>
<pageElement linkForThePage='google.com'/>
how can I open any page inside the marginal page without leaving it? is there an HTML element that do this.
in case you did not understand what I mean: I want to open other pages like google authentication as a component (like opop up but I don't want to make a popup) in my original page.
UPDATE: I had come up with the iframe approach to load a website within the component. However, all the websites with authentication pages like google, facebook will block framing.
You need to use iframe within your Component That you wanted to link to.
const MyWebSite = ({siteName})=>{
return(
<iframe src={siteName} title="My Site Name">
</iframe>
)
}
Then from Parent Component Use this Component.
<MyWebsite siteName="https://aperfectplate.co/" />
Update: While the above website will work and food app is loaded.
Codesandbox: https://codesandbox.io/s/iframe-example-nihyh?file=/src/App.js
But authentication websites will not be loaded within the component with the above approach. For example if you try below code. It wouldn't load google.com.
<MyWebsite siteName="https://www.google.com/" />
That's what I feel can be done. You may improve it later using React Router. You can make it behave like a link also. This idea could be used to build on top of :)

Change the URL of my angular app using HREF in the same domain

Is it possible to change the URL using href in html? If i'm clicking the <a href="http://localhost:4200/products.html>Products</a> from the index.html file. The url is changing 1 second and go back to the http://localhost:4200/
Even my src/app/home/home.component.html have <a href="http://localhost:4200/products.html>Products</a> is still going back to the http://localhost:4200/ when I clicked the link.
I searched a lot about this problem but all suggestion is about the routing. But I want to refresh the browser by clicking. If href is not possible please give me any idea to solve this problem. Please help me about this problem. Thank you in advance!
If you're using HTML5 mode in the $location service, you can link to the page relatively from the root of the app:
Products
That stops the $location service from rewriting the href. More: angular docs
where have you placed your products.html file because what i think is that this page is not being served on this location(localhost:4200/products.html). i am assuming that the products page is an angular component if it is then you can simply implement the click event on the tag and on click you can navigate the user to this route and refresh the app using the following code
this.router.navigateByUrl('products').then(() => {
window.location.reload();
})
if its not an angular component then you have to conform that this page is being served on the server location from which you are calling it just write the link
localhost:4200/products.html
on the browser if this page doesnot show then the problem is with the way you are serving this page to server because it means that the page is not found on this path. and you cannot call the html pages that way you are doing in localhost. just right click on the products.html file where ever it is in your computer and click on open with option choose a browzer and open file in the browzer and you will see the url on the search bar of the browzer just copy the url and paste it in href="/paste copied_url here/" and now it should open the products.html file.
Hope this helps. if you have any questions just comment.

Navigate to new page in site, keep an element loaded?

I have an iframe element that contains a music player via SoundCloud. When a user switches tabs, it reloads. Is there a way to load the new page in the background and keep the iframe as-is?
Edit
I'm using Rails.
pjax might be what you're looking for.
This gem allows you to load pages in the background using ajax and reloads only the divs you really need

Get code source of dynamically loaded HTML content (Chrome/Gmail)

I am trying to access the HTML code source of AJAX dynamically loaded content. How could I do it?
For example on Gmail, I am trying to access the HTML code of a given email discussion's content (the different entries of a given email discussion) which is loaded only when I click on this email discussion's line in the main list. The code source I can access is only the one of the page initially loaded (the list of all email discussions). Any idea?
Right-click on the page and select "Inspect Element". The element view is updated when JavaScript makes changes to the page, whereas the "View Source" view only shows content from when the page was loaded.
If you right click -> "View Source", it will show you the contents of a reloaded version of the page you are on.
Using "Inspect element" (hotkey CTRL+SHIFT+i) in Chrome shows the source of the dynamic content.
I think you want to bind event on the dom element that loaded after initial page load using ajax. If so then you can use jQuery library and you can use live method of jquery.
Here is a link for live method, you can check that.
http://api.jquery.com/live/
What you need
Download jquery latest library (http://docs.jquery.com/Downloading_jQuery)
and then include it in script within head
or you can use cdn http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
then do like following
<script>
$(document).ready(function(){
$("#ajax_dom_element_id").live('click_or_any_event',function(){
code snippet you wan dot
});
});
</script>
I think it will be helpfull.

f5 - refresh only the frame

Is it possible to refresh only one frame in the windows and not all the frames?
My problem is that i have a page index.php and inside there are two frames - menu and content. when the user clicks on refresh(f5) the index.php has been loaded again and the content page is blank.
What can i do?
If you are familiar with javascript's usage in page refresh. You can try that instead of traditional html do a job.
javascript:location.reload(false)
will do a page reload from the cache. Set this to your content page and for menu page you can set this.
javascript:location.reload(true)
What you can do is store the last page selected by the user in cookie (using client side code) then in the page load even (client side again) check for that cookie and if exists, load that page by default instead of showing blank page.
Using jQuery accessing cookies becomes really simple: http://plugins.jquery.com/project/Cookie