我试图将变量lat和lon添加到iframe网址。 javascript获取位置,然后我需要将其包含在iframe中。
如何引用lat和lon变量?
我已尝试this.lat
,vicinity.lat
等
在我的javascript中我有
var Vicinity = function (pubReference, sessionId, done, err) {
this.ad = {
getBannerHtml: function() {
return '<iframe src="http://foo.com?pr=34&lat'+ this.lat+'=&lon=' + this.lon + '"></iframe>';
}
};
this.getLatLng = function(vicinity, done, err) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(done, function(e) {
err(vicinity);
}, { enableHighAccuracy:true } );
}
};
this.init = function(done, err) {
var that = this;
this.getLatLng(that, function(position) {
that.lat = position.coords.latitude;
that.lng = position.coords.longitude;
}, err);
if(typeof done === 'function')
done(this);
};
this.init(done, err);
};
$(document).ready(function() {
var pubReference = 1;
var sessionId = "1";
var data = new Vicinity (pubReference, sessionId,
function(result) {
$("#sticky").html(result.ad.getBannerHtml());
}
);
});