我正在制作一个 Delphi XE5 VCL 窗体应用程序,主窗体上有一个 TIdHTTPServer
和 IdHTTPServer
过程的一个 CommandGet
:
procedure TForm1.IdHTTPServerCommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var responce: TStringList;
begin
if pos('someString', ARequestInfo.UnparsedParams) > 0 then
begin
responce:= TStringList.Create;
try
responce.Add('<html>');
responce.Add('<head>');
responce.Add('<title>Index</title>');
responce.Add('<script src="E:\ProjectFolder\script.js"></script>')
responce.Add('</head>');
// HTML content
responce.Add('</html>');
AResponseInfo.ContentText := responce.Text;
finally
responce.Free;
end;
end;
end;
当我更改项目目录时,浏览器看不到 .js 文件。我的问题是如何设置对 .js 文件的引用以使其在我更改项目目录时可用。
最佳答案
传统上,HTML 中的路径采用 Posix 格式(即/project/scripts/scripts.js)。也避免使用驱动器号。我会创建一个名为脚本的子文件夹,将我的 JS 文件放在其中,然后引用脚本
关于javascript - 在 Delphi VCL 应用程序中动态生成的 HTML 页面中添加对 javascript 文件的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23785609/