Open new tab without popup blocker after ajax call on user click

前端 未结 3 973
[愿得一人]
[愿得一人] 2020-12-02 12:15

I have a page that enable user to perform image manipulation via HTML5 canvas, on the page, there\'s a facebook share button for sharing a generated image of the canvas on f

3条回答
  •  臣服心动
    2020-12-02 12:52

    The answer from wsgeorge is the one that got me on the right track. Here is a function that hopefully illustrates the technique more clearly.

    function openNewAjaxTab(url) {
        var tabOpen = window.open("about:blank", 'newtab'),
            xhr = new XMLHttpRequest();
    
        xhr.open("GET", '/get_url?url=' + encodeURIComponent(url), true);
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                tabOpen.location = xhr.responseText;
            }
        }
        xhr.send(null);
    }
    

提交回复
热议问题