哈克保持history.pushState ie8-9 [英] Hack to keep history.pushState ie8-9

查看:600
本文介绍了哈克保持history.pushState ie8-9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在大多数现代浏览器上,我都可以使用:

On most modern browsers, I'm able to use:

history.pushState({}, 'Our Work','/url/path/');

显然IE不支持这个,但我想知道为什么我的简单黑客行为不起作用?

Obviously IE doesn't support this, but I'm wondering why my simple hack doesn't work?

history = {
    pushState : function(state,title,url) {
        window.location = url;
    }
};

我也试过:

window.history = {
    pushState : function(state,title,url) {
        window.location = url;
    }
};

但是我得到了未找到成员属性。

But I get a 'member not found' attribute.

IE8甚至可以实现这一点吗?

Is this even possible with IE8?

我真的不想为这个简单的黑客包含一个完整的库,但这很奇怪,因为添加:

I really didn't want to include a whole library for this simple hack, it's weird though because adding:

if (!window.console) {
    console = {
        log: function() {},
        error: function() {}
    };
}

修复我的控制台日志......

Fixes my console logs...

任何帮助都会很棒!

推荐答案

这是因为历史对象确实存在而且不能完全替换。

That is because the history object does exist and it cannot be completely replaced.

但你可以添加其他方法

所以设置

history.pushState = function(state,title,url){alert(url);};

可以解决问题。

这篇关于哈克保持history.pushState ie8-9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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