I try to display html file inside an iframe.
The html file is located inside a local folder on my server, with the relevant permissions (for example: c:\temp
).
I tried:
iframe = document.createElement("iframe");
iframe.src = "file:///c:\temp\a.html";
iframe.style.display = "block";
document.body.appendChild(iframe);
But the content is not displayed inside the iframe.
another solution I tried is to use ajax
to display the html inside a div
:
$("#DIV").html( *READ HTML TEXT FROM FILE *)
But the problem here is that I have pictures and css file included inside the html page, and they can't be displayed because the current location is my web site (they are included in c:\temp
folder with the html).
Does anyone have an idea how can I display html page with images inside an iframe
?
I try to display html file inside an iframe.
The html file is located inside a local folder on my server, with the relevant permissions (for example: c:\temp
).
I tried:
iframe = document.createElement("iframe");
iframe.src = "file:///c:\temp\a.html";
iframe.style.display = "block";
document.body.appendChild(iframe);
But the content is not displayed inside the iframe.
another solution I tried is to use ajax
to display the html inside a div
:
$("#DIV").html( *READ HTML TEXT FROM FILE *)
But the problem here is that I have pictures and css file included inside the html page, and they can't be displayed because the current location is my web site (they are included in c:\temp
folder with the html).
Does anyone have an idea how can I display html page with images inside an iframe
?
- 1 I'd move them out of the temp folder and into a folder within your web root. If the server allowed you to access and display any file on the server in the way you're trying, there would be massive security issues. – Adrian Thompson Phillips Commented Nov 20, 2012 at 9:16
- Hi @AdrianThompsonPhillips, thanks! I can access only a specific folder which has a special permission. Can't I do it without moving the files from there? – Inbal Commented Nov 20, 2012 at 9:26
- For analysis sake, does it work properly when you load the html file from the web root, instead of temp? – puddleglum Commented Nov 20, 2012 at 15:15
2 Answers
Reset to default 2The problem is that the browser sees that file:///c:\temp\a.html
as a file local to the browser, so it points to the C: drive of the visitor.
You can set up that local folder to be a Virtual Directory of your website (in IIS) and refer to the file using the correct web-path (http://...). That way you don't move the folder but it is still available through the webserver.
Assuming it works properly when you load the html file from the root instead of temp (thus, ruling out everything except an issue with the file location), you can load a file relative to your website as long as you have access. It does require understanding your path(s) - both local and server, if applicable. For instance, I have a folder called ‘temp’ on a hosted server that is a peer to my website.
Using Request.PhysicalApplicationPath, I find that my site is located here on my host: "c:\inetpub\wwwroot\mydomain.\index.htm”. Therefore my temp folder & file must be at “c:\inetpub\wwwroot\temp\myfile.txt" (again, temp is a peer to my site).
Crude Example:
string _filePath, _uriServerName = "";
_filePath = Request.PhysicalApplicationPath;
_uriServerName = Request.ServerVariables["SERVER_NAME"].ToLower();
if (_uriServerName != "localhost")
{
int rootPos = _filePath.IndexOf("wwwroot"); //get position wwwroot
_filePath = _filePath.Substring(0, rootPos) + "temp\\myfile.txt";
}
I use the above for loading files outside web site. For that, it works well. However, an iframe may present some other challenges. I don't believe this should present any cross-domain issues, but I'm not perfectly sure.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745589647a4634753.html
评论列表(0条)