Wrox Programmer Forums
|
BOOK: Professional XMPP Programming with JavaScript and jQuery
This is the forum to discuss the Wrox book Professional XMPP Programming with JavaScript and jQuery by Jack Moffitt; ISBN: 978-0-470-54071-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional XMPP Programming with JavaScript and jQuery section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 1st, 2012, 05:48 PM
Authorized User
 
Join Date: Nov 2012
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default send message on page un load

Hi Metajack,


I'm trying to send an message to all users on the onbeforeunload event for the window. So If a user navigates away or closes the browser tab, other will get that message. Below are my codes but it is not working


window.onbeforeunload = function(){ myUnloadEvent(); }
function myUnloadEvent() {
var ownjid = $('#hid_jid').val();
var curruname = ownjid.split("@");
var ownername = curruname[0].toUpperCase();

var yourid = $('#yourID').val();

var timeNow = new Date();
var hours = timeNow.getHours();
var minutes = timeNow.getMinutes();
var seconds = timeNow.getSeconds();
var timeString = "" + ((hours > 12) ? hours - 12 : hours);
timeString += ((minutes < 10) ? ":0" : ":") + minutes;




var allpubval = $('#pubroomval').val();
var text = 'save';
allpubval = allpubval.split('##');
var ulength = allpubval.length;
for(var i=0;i<ulength;i++){
var sendjid = allpubval[i];
Arthur.connection.sync = true;
var msg = $msg({to: sendjid, type: 'chat',stamp: timeString, pname: ownername,pid: yourid,modetype: 'public'}).c('body').t(text);
Arthur.connection.sync = true;
Arthur.connection.send(msg);
Arthur.connection.flush();
}


}
 
Old December 2nd, 2012, 01:18 AM
Wrox Author
 
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
Default

I don't have much experience with onbeforeunload, but this patch may help:
https://github.com/metajack/strophejs/issues/16

The problem is that XHR is asynchronous, so the requests don't finish before the page is destroyed.
 
Old December 2nd, 2012, 03:17 AM
Authorized User
 
Join Date: Nov 2012
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Metajack,

I could not able to see this patch in the core.js which is in the github. But I added the below thing in my strophe.js and found that it is still incorrect.

//req.xhr.open("POST", this.service, true); //commented this line
var async = !('sync' in this && this.sync === true);//added this line
req.xhr.open("POST", this.service, async);

Please tell me If I am wrong and also help to how I can add this functionality.

Thanks
 
Old December 3rd, 2012, 03:09 PM
Authorized User
 
Join Date: Nov 2012
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Metajack,

Please let me know to my above written points.

Thanks
 
Old December 5th, 2012, 11:28 AM
Authorized User
 
Join Date: Nov 2012
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Metajack,

Please take a look at this post and let me know how I can send a stanza before browser close. I have applied the above patch but it is not working.

Thanks
 
Old January 19th, 2013, 05:39 PM
Authorized User
 
Join Date: Nov 2012
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Metajack,

I need your urgent help in this , please guide me here.

Thanks
 
Old January 19th, 2013, 11:12 PM
Wrox Author
 
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
Default

Sorry, I'm not sure what I can do to help. I don't have any experience with this issue directly, and I don't have the time to go dig into myself.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Send Message to Email inbaa ASP.NET 1.0 and 1.1 Professional 2 August 28th, 2006 05:45 AM
send message to many recipients eda BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 May 29th, 2006 08:49 PM
Send a Message box to another machine red4vbs VBScript 3 January 31st, 2005 04:33 PM
How to send message to SMS !!!!! stevenThu Classic ASP Professional 4 August 26th, 2004 10:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.