I'm generating a pdf on Grails using the following pattern:
Optional Step: The user will choose either he wants to download the *.pdf or to open it on another tab, the default is to open it to another tab.
Main Step:
It will run a block of JavaScript something like this:
var generate = "<sample url>" // some amazing processing goes here that appends data to the // query string. window.open(generate,'_blank');
Then it will open a new tab (or start downloading, depending on the option he had chosen).
Note: The opened tab is not an ordinary html markup, but rather a
I already generated the reports successfully (both the new tab and the download approach), however my problem is I don't know how to detect if that tab has finished loading , and I cannot do step 7. Can anyone help me how to implement this?
You can use Spring Websocket to send the status of the generation back to the JavaScript, like this
<script type="text/javascript">
$(function () {
var socket = new SockJS("${createLink(uri: '/stomp')}");
var client = Stomp.over(socket);
client.connect({}, function () {
client.subscribe("/topic/generatePdf", function (message) {
console.log(message);
$("#bnt").value(JSON.parse(message.body));
});
});
$("#bnt").click(function() {
client.send("/app/generatePdf", {}, JSON.stringify({
'type': 'foo',
'id':2
}));
});
});
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.