I am trying to call a script in an IFrame from the parent page from the code behind. C # I use to call a function:
protected void Page_Load(object sender, EventArgs e) { ... string scr = "document.getElementById('mapframe').contentWindow.addPoint(0, 0);" ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), scr , true); }
iFrame HTML:
<iframe name="mapframe" id="mapframe" src="Map.html" style="width:100%;height:360px;"></iframe>
And Javascript in IFrame:
function addPoint(lat, lon) { var myLatlng = new google.maps.LatLng(lat, lon); var marker = new google.maps.Marker({ position: myLatlng, map: map, title: "Hit" }); }
However, this causes this error: "Unable to get the" addPoint "property from undefined or null reference." What causes this error? I checked that the contentWindow was not null.
source share