I'm updating this post as the sample below was pretty old, this new sample is from DM and uses the new 0.7 gadgets stuff. Note that since calling "new opensocial.Surface" was never allowed, it's now broken from the 0.6->0.7 migration, making the original sample even more deprecated.
updated sample
<select id="ddl_canvas">
<option value="home">home</option>
<option value="profile">profile.left</option>
<option value="profile.right">profile.right</option>
<option value="canvas">canvas</option>
</select>
<br>
Value One: <input type="text" id="txtParamOne" />
<br>
Value Two: <input type="text" id="txtParamTwo" />
<br>
<input type="button" onclick="navigate()" value="Submit" />
<script type="text/javascript" id="MSOS_HOME">
function navigate(){
var params = {};
var isPrimary = false;
var surfaceName = document.getElementById('ddl_canvas').value;
if (surfaceName === 'canvas')
isPrimary = true;
var surfaces = gadgets.views.getSupportedViews();
var surfaceRef = surfaces[surfaceName];
params['param1'] = document.getElementById('txtParamOne').value;
params['param2'] = document.getElementById('txtParamTwo').value;
gadgets.views.requestNavigateTo(surfaceRef, params);
}
function init() {
var params1 = opensocial.getEnvironment().getParams();
if ('undefined'===typeof(params1) || 'undefined' === typeof(params1['param1'])){
return;
}
document.getElementById('txtParamOne').value = params1['param1'];
document.getElementById('txtParamTwo').value = params1['param2'];
}
init();
</script>
----------------- old post below -----------------------
See below for a sample widget that navigates between surfaces and passes arbitrary values around (thanks for the code Donny). Note that you can't navigate from Home to anywhere at this time but all other permutations should work. Also note that right now any opt_params passed into rNT will end up on the other end under this object:
opensocial.getEnvironment().getParams().appParams
This is a bug, in the future the objects will be accessed directly under getParams() as per the opensocial spec (and not under appParams).
<select id="ddl_canvas">
<option value="home">home</option>
<option value="profile">profile.left</option>
<option value="profile.right">profile.right</option>
<option value="canvas">canvas</option>
</select>
<br>
Value
One: <input type="text" id="txtParamOne"
/>
<br>
Value
Two: <input type="text" id="txtParamTwo"
/>
<br>
<input type="button" onclick="navigate()" value="Submit" />
<script type="text/javascript" id="MSOS_HOME">
function navigate(){
var params
= {};
var isPrimary
= false;
var surfaceName
= document.getElementById('ddl_canvas').value;
if (surfaceName === 'canvas')
isPrimary =
true;
var canv
= new
opensocial.Surface(surfaceName, isPrimary);
params['param1'] = document.getElementById('txtParamOne').value;
params['param2'] = document.getElementById('txtParamTwo').value;
opensocial.requestNavigateTo(canv, params);
}
function init() {
var params1
= opensocial.getEnvironment().getParams().appParams;
if ('undefined'===typeof(params1) || 'undefined' === typeof(params1['param1'])){
return;
}
document.getElementById('txtParamOne').value = params1['param1'];
document.getElementById('txtParamTwo').value = params1['param2'];
}
init();
</script>