Creating an eMail link once a test has finished

The tutorial below explains how to set up the applet to pass the results of a test to a JavaScript function and then use JavaScript to display a link used to email the results.

Step 1

The <param> that needs to be added to your applet code is:

<param name="js" value="">

Where the value is the JavaScript function and parameters passed. So the applet code may look like this:

<applet MAYSCRIPT name="myspeed" code="myspeedserver/applet/myspeed.class" archive="myspeed.jar,/myspeed/plugins.jar" width="600" height="400">
<param name="js" value="">
<param name="testspecid" value="-2"></param>
Java is required to view this applet </applet>

Step 2 explains how to fill in the "value=" part of the param.

Step 2

For this tutorial we are going to pass a few variables that would relate to a MySpeed test. A full list of all variables for all plug-ins can be found in the JS reporting section of the manual applet configuration within MyConnection Server (http://www.myconnectionserver.com/support/v9/manualappletconfig.html

<param name="js" value="mys($SPEED.DSPEED$,$SPEED.USPEED$,$SPEED.QOS$,$SPEED.RTT$,$SPEED.MAXPAUSE$)">

The code above will run a JavaScript function called "mys" and pass the parameters specified. In this case they are download speed, upload speed, quality of service, round-trip time and maximum delay.

Step 3

The JavaScript function now needs to be written to deal with the parameters passed and then provide a link to launch a new email with the results included. The example JavaScript below will do just that.

The location of where the link appears is governed by the position of a <div> within the HTML of your page. A full, copy and pasteable example will be given at the end of this tutorial. In this example the correct div format should be:

<div id="elink"></div>

The JavaScript needed is:

<script>
var _ebody;
function addCommas(n) {
var s=""+n;
var len = s.length;
for (var at=len-3; (at>0); at-=3) {
s = s.substring(0,at)+","+s.substring(at);
}
return s;
}

function mys(dspeed,uspeed,qos,rtt,maxp) {
_ebody = "";
_ebody += "Visualware MySpeed Test Results\n\n";
_ebody += "The MySpeed test results below show Speed and Quality measurements\n";
_ebody += "\n";
_ebody += "URL: " + location.href+"\n";
_ebody += "When: " + new Date()+"\n";

_ebody += "Download: " + addCommas(dspeed)+" bps\n";
_ebody += "Upload: " + addCommas(uspeed)+" bps\n";
_ebody += "QOS: " + qos+"%\n";
_ebody += "RTT: " + rtt+" ms\n";
_ebody += "MaxPause: " + maxp+" ms\n";
var s = '<a href="javascript:emailnow()"><b>Click to email these results</b></a><br><br>';
document.getElementById('elink').innerHTML = s;
}
function emailnow() {
document.location.href = "mailto:myspeed@company.com?subject=MySpeed Test Results&body="+escape(_ebody);
}

</script>

Step 4

Copying and pasting everything below into the HTML of your page (paste it where you would like the applet to appear) will get you 99% of the way there. The only thing that needs changing is in bold below. The codebase in this example is set to our server, simply change this entry to your own MyConnection Server address.

<!-- The Javascript below creates the email body from the results of the speed test -->
<script>

var _ebody;
function addCommas(n) {
var s=""+n;
var len = s.length;
for (var at=len-3; (at>0); at-=3) {
s = s.substring(0,at)+","+s.substring(at);
}
return s;
}
function mys(dspeed,uspeed,qos,rtt,maxp) {
_ebody = "";
_ebody += "Visualware MySpeed Test Results\n\n";
_ebody += "The MySpeed test results below show Speed and Quality measurements\n";
_ebody += "\n";
_ebody += "URL: " + location.href+"\n";
_ebody += "When: " + new Date()+"\n";

_ebody += "Download: " + addCommas(dspeed)+" bps\n";
_ebody += "Upload: " + addCommas(uspeed)+" bps\n";
_ebody += "QOS: " + qos+"%\n";
_ebody += "RTT: " + rtt+" ms\n";
_ebody += "MaxPause: " + maxp+" ms\n";
var s = '<a href="javascript:emailnow()"><b>Click to email these results</b></a><br><br>';
document.getElementById('elink').innerHTML = s;
}

function emailnow() {
document.location.href = "mailto:myspeed@company.com?subject=MySpeed Test Results&body="+escape(_ebody);
}

</script>

<!-- The applet code below displays the MySpeed applet -->

<applet mayscript name="mcs" code="myspeedserver/applet/myspeed.class" archive="/myspeed/myspeed.jar,/myspeed/plugins.jar" codebase="http://mcslhr.visualware.com/myspeed" width=600 height=400>
<param name="testspecid" value="-2">
<param name="js" value="mys($SPEED.DSPEED$,$SPEED.USPEED$,$SPEED.QOS$,$SPEED.RTT$,$SPEED.MAXPAUSE$)">
</applet>

<!-- The DIV below is where the email link will appear once the test has finished -->

<br><br>
<div id="elink"></div>

Below is a working example in action:



Visualware Home | Contact Us | About Us