我有一個TIdHTTPServer
,它將HTML代碼中的javascript代碼發送到瀏覽器,代碼中的代碼爲<script language="javascript">
。我無法訪問html文件,因此我無法更改它的內容。我用HTTPServerCommandGet
這個文件的內容發送到瀏覽器這樣的:Indy TIdHTTPServer OnCommand在html中執行javascript未執行
procedure TMainForm.HTTPServerCommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
responseMemoryStream : TMemoryStream;
begin
responseMemoryStream := TMemoryStream.Create;
try
AResponseInfo.ContentType := 'text/html';
AResponseInfo.ContentEncoding := 'UTF-8';
AResponseInfo.CharSet := 'UTF-8';
responseMemoryStream.LoadFromFile(ExtractFilePath(Application.ExeName) + 'index.html');
AResponseInfo.ContentStream := TMemoryStream.Create;
TMemoryStream(AResponseInfo.ContentStream).LoadFromStream(responseMemoryStream);
finally
responseMemoryStream.Free;
end;
end;
當我然後再到有時加載JavaScript的互聯網瀏覽器GET
命令,但有時沒有 - 當我使用Firefox沒有問題,但是當我使用Chrome或IE JavaScript從不執行。有沒有辦法用AResponseInfo
變量以某種方式強制執行javascript代碼,或者我沒有辦法解決這個問題?
這就是index.html
的部分看起來像:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta charset=utf8 />
<title>My title</title>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script language="javascript">
var map;
var flag_for_map_massage = 0;
var map_marker = 0;
function initmap()
{
var html;
var map_divtxt = "<div id=\"map_canvas\" style=\"width:200px;height:150px;\" ></div>";
document.getElementById("google_map").innerHTML = map_divtxt;
var latlng = new google.maps.LatLng(100.12345, 200.12345);
var options = {
zoom: 17,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map1 = new google.maps.Map(document.getElementById("map_canvas"), options);
var html = "<table>" +
"<tr><td>GMBH Address</td> </tr>";
infowindow = new google.maps.InfoWindow({
content: html
});
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(100.12345, 200.12345),
map: map1
});
// infowindow.open(map1, marker1);
google.maps.event.addListener(marker1, "click", function() {
infowindow.open(map1, marker1);
});
}
</script>
</head>
<body onload="initmap();">
<div class="entry">
<div id="google_map">
</div>
</div>
</body>
</html>
我剛剛看到這段代碼'var latlng = new google.maps.LatLng(100.12345,200。12345);當''OnCommandGet''發送時''不能被執行(後面的所有內容),但如果我用瀏覽器打開文件本身 - 它會執行正常。 – 2014-11-25 13:56:36
@whosrdaddy - 無處 - 顯然它們會以某種方式自動加載(當我在本地加載文件後檢查瀏覽器中的元素時,我會在「
」標記中看到3個Google Maps API''',並且它只能在Firefox中使用 - IE和Chrome無法加載地圖。 – 2014-11-25 14:26:55