当URI太长时,Chrome会崩溃 [英] Chrome crashes when URI is too long

查看:242
本文介绍了当URI太长时,Chrome会崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的HTML5游戏制作导出功能,我目前的保存方法是游戏数据的原始序列化然后:

I'm making an export function to a HTML5 game of mine and my current saving method is a crude serialization of game data and then:

// this is Javascript
var gameData = "abc"; // this is actually a HUGE string of over 2MB
try
{
    document.location = "data:text/octet-stream,"+encodeURIComponent(JSON.stringify(gameData));
}
catch(e)
{
    console.log(e);
}

来自:使用HTML5 / Javascript生成并保存文件

我不介意我无法使用它大字符串,但我希望它生成一个警告,通知此方法不起作用,不幸的是Chrome(16)崩溃而没有捕获该异常。

I don't mind the fact that I can't use it for big strings, but I'd like it to generate a warning that informs that this method doesn't work, unfortunately Chrome (16) crashes without catching that exception.

是有更好的方法来实现这种出口,对我来说重要的是让它在本地工作。 FileAPI 将是一个更好的解决方案,但不能在本地运行。

Is there a better way to implement this kind of export, the important thing being for me is to make it work locally. FileAPI would be a better solution, but doesn't work locally.

推荐答案

AFAIK不可能是客户端;但是这样可以在Chrome中保存1.99MB文件;也许你应该尝试压缩/优化你的游戏数据。一种方法是使用 JSZip

AFAIK not possible client-side; but a 1.99MB file can be saved this way in Chrome; maybe you should try to compress/optimize your game data a little bit. One way to do that is to use JSZip.

为了检查当前浏览器是否是谷歌浏览器,因此该方法不适用于长字符串,您可以使用以下内容:

In order to check if the current browser is Google Chrome and so the method doesn't work with long strings you can use something like this:

if(gameData.length > 1999999 && window.chrome){
    alert("Sorry, this export method does not work in Google Chrome")
    return; 
}

这篇关于当URI太长时,Chrome会崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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