我在页面上有一个"新项目"徽章,我想立即更新页面从缓存中加载(即,当点击"返回"或"转发"返回此页面时).完成此任务的最佳方法是什么?
设置非常简单.应用程序的布局每8秒查找一个新项目,并相应地更新徽章+项目列表.
$(function() {
setInterval( App.pollForNewItems, 8000 );
});
Run Code Online (Sandbox Code Playgroud)
当有人导航离开此页面以查看项目的详细信息时,可能会发生很多事情.在任何用户查看之前,事情都是"新的" ,并且应用程序可能会有多个用户同时使用它(用于呼叫中心或支持服务单的工作流程类型).
为了确保徽章始终是最新的,我有:
$(window).bind('focus load', function ( event ) {
App.pollForNewItems();
});
Run Code Online (Sandbox Code Playgroud)
..虽然这有效,但只有在从缓存加载页面时,轮询"加载"上的新项目才有用.是否有可靠的跨浏览器方式来判断是否正在从缓存加载页面?
javascript jquery javascript-events browser-cache browser-history
所有这3个库都允许操纵历史对象.好吧,骨干做了很多但是只考虑它的历史部分.
这3个实现有什么区别?
嘿,我statechange在窗口上设置了以下事件:
History.Adapter.bind(window,'statechange',function(e){
console.log("statechange event occured ");
//more code
var newDoc = document.open();
newDoc.write(file);
newDoc.close();
});
Run Code Online (Sandbox Code Playgroud)
我正在使用history.js,但在这种情况下无关紧要,因为它会定期绑定statechange,我得到的值file应该是并且工作正常.
现在我在外部js文件中有这个代码(和其他代码),在我遍历所有a标签的文件中并应用以下click事件:
$(element).on("click",function(e){
e.preventDefault();
//more code
History.pushState({file : file},title, fullHref);
});
Run Code Online (Sandbox Code Playgroud)
现在当我点击文档时按预期更改但是当尝试使用后退/前进按钮时,statechange事件不会触发.
我应该提一下,这个js也包含在我加载的文件中.
所以我最初的想法是,当文档发生变化但窗口没有变化时,事件仍然存在.这是不正确的,因为它应用statechange事件多次时间.所以我尝试使用cookie一次应用该事件,但仍然做同样的事情.
现在,如果不是更改文档而是简单地将其应用于jQuerys .html(),则statechange 事件将被触发,因此我猜它与文档有关.
为什么会这样?我相信如果我更多地了解在更换文档时窗口事件会发生什么,我可以解决这个问题.
尝试:
popstate通过常规的历史API 绑定到事件,仍然提供相同的结果.pushState不会激活popstate,但后退按钮确实没有状态.on相同的结果信息:
我在mdn中读过:
{{gecko_minversion_note("1.9.2","从Gecko 1.9.2开始,document.open()使用
它使用的URI的文档的主体,而不是从堆栈中取出主体.因此,即使使用wrappedJSObject,也无法再将chrome.write()调用到chrome中的不受信任的文档中.")}}
我不确定,但我认为可以解决这个问题
我会开始研究一下,但没有解决方案可以解决看起来应该是一个简单的JQM修改.
我有一个葡萄酒评论webapp,具有以下视图用户流程:http: //5buckchuck.com/
葡萄酒类型>酒单>葡萄酒详情>葡萄酒评论(通过django backto重定向)>葡萄酒详细信息从评论更新
我想要发生的是当用户按下后退按钮时它应该返回到酒单.目前发生的是重新加载Wine Detail视图.需要三次回压才能回到酒单.:-(
我解决这个问题的想法是两个:
如果历史堆栈中的最后一项是Wine Review,则拼接历史堆栈中的最后3项.我很难尝试内省最后一个历史对象来获取pageURL.我觉得这个解决方案有点太脆弱了.
var last_hist = $.mobile.urlHistory.getActive();
last_hist.data.pageURL;
Run Code Online (Sandbox Code Playgroud)第二个想法是覆盖后退按钮行为,以便Wine Detail视图中的后退按钮始终返回到Wine列表视图
$('div#wine_detail').live('pageshow',function(event, ui){
$("a.ui-btn-left").bind("click", function(){
location.replace("/wines/{{wine.wine_type}}/#");
});
});
Run Code Online (Sandbox Code Playgroud)可能有更好的方法来做到这一点,但我有点想法.
更新:所以我继续以一些可以忽略不计的结果来破解这个问题.在我发现的事情上,这是我基本上需要工作的东西:window.history.go(-3)
从控制台它完全符合我的需要.
所以我尝试将后面的按钮绑定到这样:
$('div#wine_detail').live('pageshow',function(event, ui){
var last = $.mobile.urlHistory.stack.length - 1;
var last_url = $.mobile.urlHistory.stack[last].url;
var review_url = /review/g;
if (last_url.match(review_url) )
{
$('div#wine_detail a.ui-btn-left').bind( 'click', function( ) {
console.log("click should be bound and going back in time...")
window.history.go(-2);
});
}
else
{
console.log('err nope its: ' + last_url);
}
});
Run Code Online (Sandbox Code Playgroud)
没有骰子,有些东西会中断交易......
这就是我用来打开具有给定URI的浏览器的方法
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com/"));
startActivity(browserIntent);
Run Code Online (Sandbox Code Playgroud)
有没有办法可以用以前访问过的页面打开浏览器.或者说只需打开浏览器,即可显示上次查看的页面.
目的:
在应用程序中,要求用户提交URL,因此它不是键入,而是有一个选项Open Browser,以便他/她可以复制URL,返回并提交.最后一个URL很可能是他/她想要提交的内容
编辑:
我可以使用浏览器历史记录获取最后访问过的页面
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />
Run Code Online (Sandbox Code Playgroud)
但在安装应用程序时,它说:
此应用程序将读取您的浏览器历史
在看到,没有人安装.
有什么方法可以改变浏览器设置,如果我在离开的地方继续?
我正在一个与身体/心理虐待者有关的网站上工作.
始终有一个紧急退出按钮,因此用户可以在"激进"的人进入计算机所在的房间之前单击它.
当用户点击紧急按钮时,用户会自动被重定向到Google,其查询类似于"烹饪苹果派"(这是一个示例).
此外,我们希望隐藏我们的网站与浏览器历史记录,以防攻击者检查被虐待者的历史.我认为这不可能在技术上完成.
至少,我们是否可以生成虚假的浏览历史记录,以便在用户访问我们网站时为侵略者辩护?
我尝试了多种方法来模拟"浏览",例如使用iframe或ajax查询到另一个网站,但没有填充浏览器历史记录.
这可以吗?
谢谢您的意见!
我正在使用jQuery动态加载div容器中的内容.
服务器端代码检测请求是AJAX还是GET.
我希望浏览器后退/前进按钮使用代码,所以我尝试使用history.pushState.我必须遵循一段代码:
$('.ajax').on('click', function(e) {
e.preventDefault();
$this = $(this);
$('#ajaxContent').fadeOut(function() {
$('.pageLoad').show();
$('#ajaxContent').html('');
$('#ajaxContent').load($this.attr('href'), function() {
window.history.pushState(null,"", $this.attr('href'));
$('.pageLoad').hide();
$('#ajaxContent').fadeIn();
});
});
});
Run Code Online (Sandbox Code Playgroud)
一切正常,除非使用浏览器后退/前进按钮浏览时,栏中的地址会根据计划更改,但页面不会更改.我究竟做错了什么?
在Clayton的回答帮助下更新了脚本
var fnLoadPage = function(url) {
$('#ajaxContent').fadeOut(function() {
$('.pageLoad').show();
$('#ajaxContent').html('').load(url, function() {
$('.pageLoad').hide();
$('#ajaxContent').fadeIn();
});
});
};
window.onpopstate = function(e) {
fnLoadPage.call(undefined, document.location.href);
};
$(document).on('click', '.ajax', function(e) {
$this = $(this);
e.preventDefault();
window.history.pushState({state: new Date().getTime()}, '', $this.attr('href'));
fnLoadPage.call(undefined, $this.attr('href'));
});
Run Code Online (Sandbox Code Playgroud) 在OSS Web应用程序中,我们有JS代码执行一些Ajax更新(使用jQuery,不相关).页面更新后,将调用html5历史记录界面History.pushState,代码如下:
var updateHistory = function(url) {
var context = { state:1, rand:Math.random() };
/* -----> bedfore the problem call <------- */
History.pushState( context, "Questions", url );
/* -----> after the problem call <------- */
setTimeout(function (){
/* HACK: For some weird reson, sometimes something overrides the above pushState so we re-aplly it
This might be caused by some other JS plugin.
The delay of 10msec allows the other plugin to override the URL.
*/
History.replaceState( context, "Questions", …Run Code Online (Sandbox Code Playgroud) 是否可以在加载页面后通过JavaScript更改浏览器历史记录中页面的标题?应该是跨浏览器(当然)并且在不支持HTML5 History API的浏览器上工作,我的主要目标浏览器是Chrome.
我已经尝试了很多方法,但它们似乎都不可靠.这是我上次尝试过的(history.js):
<html>
<head>
<title>Standard title</title>
<script src="https://rawgit.com/browserstate/history.js/master/scripts/bundled-uncompressed/html4%2Bhtml5/native.history.js"></script>
</head>
<body>
<script>
window.setTimeout(function(){
document.title = "My custom title";
History.replaceState({}, "My custom title", window.location.href);
}, 3000);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果我在页面加载Standard title后3秒内在Chrom中加载历史页面,我看到,在3秒后我得到了My custom title.
为什么我需要这个:我有一个只适用于JavaScript的应用程序(Angular 1),它运行在不同的环境(开发,测试,生产)上.我想显示一个标题MyApp (<environmentName>),但我不想为每个环境构建我的应用程序的单独版本.相反,应用程序可以通过AJAX从后端请求环境信息并更新页面标题.所有这一切都很好(页面标题得到更新),但浏览器历史记录仍显示"标准"标题.
有没有办法在浏览器历史记录中更改页面的标题?
切换到路由器v4和历史v4.5.1,现在历史监听器无法正常工作
import createBrowserHistory from 'history/createBrowserHistory'
const history = createBrowserHistory()
history.listen((location, action) => {
console.log(action, location.pathname, location.state) // <=== Never happens
})
render(
<Provider store={store}>
<Router history={history}>
...
</Router>
</Provider>,
document.getElementById('root')
)
Run Code Online (Sandbox Code Playgroud)
有什么想法被忽略的想法?
browser-history ×10
javascript ×7
jquery ×3
history.js ×2
html5 ×2
android ×1
angularjs ×1
backbone.js ×1
browser ×1
django ×1
dom ×1
pushstate ×1
react-router ×1
reactjs ×1
redux ×1
urlencode ×1
web ×1