从刷新停止主页 [英] Stop Home Page From Refreshing

查看:51
本文介绍了从刷新停止主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Javascript应用程序,它利用WinJS.Navigation.navigate()来浏览单页面应用程序。 当用户点击主页上的链接到另一个页面,然后点击后退按钮,主页不保留页面上的
原始状态/数据,页面重新加载,就好像应用程序一样已重新启动。 


$
我们如何让主页保持其原始状态?

We have a Javascript app that utilizes WinJS.Navigation.navigate() to navigate the single page application.  When the user clicks a link on the home page to another page, then clicks the back button, the home page does not retain the original state/ data on the page, the page reloads as if the application has been restarted. 

How do we get the home page to retain its original state?

我们的代码基于以下示例:



http://msdn.microsoft.com/en-US/library/windows/apps/hh452768

Our code is based on the example here:

http://msdn.microsoft.com/en-US/library/windows/apps/hh452768



以下是我们正在使用的代码。  


Below is the code we are using.  

在home.js文件中



function ()
{

In the home.js file

(function() {

" use strict" ;

"use strict";

    WinJS.UI.Pages.define(" / pages / home / home.html",{

    WinJS.UI.Pages.define("/pages/home/home.html", {

        }

        }

    });

    });

功能 linkClickEventHandler(eventInfo)
{

functionlinkClickEventHandler(eventInfo) {

        eventInfo.preventDefault();

        eventInfo.preventDefault();

     ;     WinJS.Navigation.navigate(link.href);    }

        WinJS.Navigation.navigate(link.href);    }

})();              


主页上的链接使用以下链接和文本框字段调用页面片段:

< a
href =" /pages/help/Help.html"> 帮助 < / a >

 })();              
A link on the home page calls the page fragment with the following link and text box field:
<a
href="/pages/help/Help.html">Help</a>

< input type =" text" id =" txtTest" />

<inputtype="text"id="txtTest"/>

当用户导航到帮助页面(Help.html),然后点击返回,重新加载主页,清除文本框
field txtTest。 

推荐答案

你可以使用可跨页面访问的全局变量.....比如使用数据页中的命名空间定义和公开变量(data.js可能是...)。

you may use global variables which can be accessed across pages..... like define and expose the variable using the namespace in your data page (data.js may be...).

如果它不为null,则设置值....

in case if it is not null, set the values....

其他方式可以使用history.back .....但是,你可能会显示一些可能不合适的陈旧/旧数据

other way can be using history.back..... but then, you may be displaying some stale /old data which may not be appropriate


这篇关于从刷新停止主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆