How to get the exported image without moving from the current window when using mobile devices

99封情书 提交于 2019-12-14 03:20:03

问题


I'm using Highcharts to draw data as diverse graphs.

As you already know, if I add the exporting.js file in the HTML document,

then it will display a small button on your top-right area within Highcharts' canvas

The current problem happens when I use a smartphone.

When I try to export the current graph, the current browser window is closed.

I can download the file, but the previous window is gone.

How can I modify Highcharts?

I want to open the new window when I click one of the export options.

Thanks in advance.


回答1:


I noticed this issue on iOS devices. However there's a quite simple workaround. By default highcharts creates hidden <form> element and submits data to the exporting server. What we can do here is specifying form's target attribute.

So, here's a drop-in fix that overrides default Highcharts exporting module (just put it after exporting.js)

Highcharts.post = function (url, data) {
    var createElement = Highcharts.createElement,
        discardElement = Highcharts.discardElement,
        name,
        form;

    // create the form
    form = createElement('form', {
        method: 'post',
        action: url,
        enctype: 'multipart/form-data',
        target: '_blank'
    }, {
        display: 'none'
    }, document.body);

    // add the data
    for (name in data) {
        createElement('input', {
            type: 'hidden',
            name: name,
            value: data[name]
        }, null, form);
    }

    // submit
    form.submit();

    // clean up
    discardElement(form);
};

Here you can find a working demo: http://jsfiddle.net/dWfv5/




回答2:


Since Highcharts 3.0.8 (2014-01-09) you can set the target as an option, so you don't need the drop-in fix.

Specify the target as part of the exporting.formAttributes like so:

    exporting: {
        formAttributes: {
            target: '_blank'
        }
    }

Live demo at http://jsfiddle.net/highcharts/dWfv5/4/



来源:https://stackoverflow.com/questions/15837282/how-to-get-the-exported-image-without-moving-from-the-current-window-when-using

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!