Re: Running JavaScript on Delphi web browser



"Mark Dradey" <markd@xxxxxxxxxxxxxxxxxxx> schreef in bericht
news:k5KdneemZctyAnvbnZ2dnUVZ8qWhnZ2d@xxxxxxxxx
Hi,

I am trying to see if I can integrate Google maps into my Delphi
application. I have found some JavaScript which would take parameters, see
http://www.stevetrefethen.com/files/googlemap.htm What I can't work out is
how to run that JavaScript from Delphi. Can anyone help me.


The way I've tackled this (using TwebBrowser) is as follows (apart from
declarations, try's, etc):

1) construct the javascript as part of a complete HTML file. Eg:
txt:='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN '+
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>'+nlcr+
'<html xmlns="http://www.w3.org/1999/xhtml";>'+nlcr+
'<head>'+nlcr+
'<meta http-equiv="content-type" content="text/html;
charset=utf-8">'+nlcr+
'<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='+
preferences.GoogleMAPSkey+'" '+
'type="text/javascript"></script>'+nlcr+
'<script type="text/javascript">'+nlcr+
'//<![CDATA['+nlcr+
' function load() {'+nlcr+
' if (GBrowserIsCompatible()) {'+nlcr+
' var map = new GMap2(document.getElementById("map"));'+nlcr+
' map.addControl(new GSmallMapControl());'+nlcr+
' var zoomLevel = map.getBoundsZoomLevel(new GLatLngBounds('+
GLatLng(minLAT,minLONG)+','+GLatLng(maxLAT,maxLONG)+'));'+nlcr+
' map.setCenter('+GLatLng((minLAT+maxLAT) DIV
2,(minLONG+maxLONG) DIV 2)+',zoomLevel);'+nlcr+
' map.enableDoubleClickZoom();'+nlcr+
' map.enableContinuousZoom();'+nlcr+
'
GEvent.addListener(map,"mousemove",function(){map.closeInfoWindow()});'+nlcr+
markers+

' GEvent.addListener(map, "click", function(overlay,
point){'+nlcr+
' map.clearOverlays();'+nlcr+
' if (point) {'+nlcr+
' var DragMarker = new GMarker(point, {icon:G_DEFAULT_ICON,
draggable: true});'+nlcr+
' map.addOverlay(DragMarker);'+nlcr+
' DragMarker.enableDragging();'+nlcr+
' map.panTo(point);'+nlcr+
' var lat100 =Math.round(point.lat()*100);'+nlcr+
' var long100=Math.round(point.lng()*100);'+nlcr+
' msg = "LAT: <B>"+lat100+"</B> &nbsp; LONG:
<B>"+long100+"</B>";'+nlcr+
' document.getElementById("pointRef").innerHTML = msg;'+nlcr+
' GEvent.addListener(DragMarker,"drag",function(){'+nlcr+
' var lat100
=Math.round(DragMarker.getPoint().lat()*100);'+nlcr+
' var
long100=Math.round(DragMarker.getPoint().lng()*100);'+nlcr+
' msg = "LAT: <B>"+lat100+"</B> &nbsp; LONG:
<B>"+long100+"</B>";'+nlcr+
' document.getElementById("pointRef").innerHTML = msg;'+nlcr+
' });'+nlcr+
' }'+nlcr+
' });'+nlcr+

' }'+nlcr+
' }'+nlcr+
'//]]>'+nlcr+
'</script>'+nlcr+
'</head>'+nlcr+
'<body style="font-family:Arial" onload="load()"
onunload="GUnload()">'+nlcr+
' <table width=100%>'+nlcr+
' <tr><td id="map" style="height:254px">'+nlcr+
' <tr><td id="pointRef" align=right style="font-size:10pt">'+s+
' </table>'+nlcr+
'</body>'+nlcr+
'</html>';

2) write the string to a disk file:
assignFile(textfile,filename);
rewrite(textfile);
writeln(textFile,txt);
flush(textfile);
CloseFile(textFile);

3) call the file from the TwebBrowser:
webBrowser.Navigate(Filename);

Tom


.



Relevant Pages

  • Re: on page exit
    ... of which JavaScript is only one. ... used in HTML with intrinsic event handler attribute values, ... var clickedLink = null; ...
    (comp.lang.javascript)
  • Re: Highlighter
    ... JavaScript, but during this project, I have to admit, I am not the ... var where, ergebnis; ... Say you try to highlight 'color' and there is an element somewhere on the page that has a style attribute with a setting for the color or background-color property - I think you can see where this will go horribly wrong. ...
    (comp.lang.javascript)
  • dynamically building and evaluating expressions in javascript (functionally)
    ... I'm a relative newbie to javascript and functional programming, ... user of my webpage to be able to filter this list any way he wants. ... var mylist; //temp list which will contain my results ...
    (comp.lang.functional)
  • Re: VBScript versus JavaScript
    ... gc holds a reference to the textbox. ... var gc = document.FORM1.txtGCPHNO.value ... > Is there any way I can get away from using JavaScript? ... If you are talking about using script in a browser then VBScript only works ...
    (microsoft.public.scripting.vbscript)
  • Re: Can Jscript source code be visible in a browser?
    ... > what we can do as web developers to hide JavaScript. ... var ContextWindow = window.open; ... So, I just typed the URL into my browser, and was prompted to run or save ... > Your analogy against my suggestion doesn't seem to be correct. ...
    (microsoft.public.dotnet.framework.aspnet)