Html 在 iframe 中显示本地 htm 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11152103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Displaying local htm file in iframe?
提问by Ahmed
I am saving some emails on my local machine using MailBee.NET Objects in htm format. A separate folder is created for each email using email messageID on server for example
我正在使用 Htm 格式的 MailBee.NET 对象在我的本地机器上保存一些电子邮件。例如,使用服务器上的电子邮件 messageID 为每封电子邮件创建一个单独的文件夹
D:\Emails\GmailId1380ec660e0e656a\doc.htm
D:\Emails\GmailId1380ec660e0e656a\doc.htm
is an email downloaded from gmail. I am saving also the above mentioned path in database so I can use it later. Now I am trying to display this htm file in an iframe but it is not working. A user clicks on email which takes him to the read_email page on which I am trying to assign the path mentioned above to an iframe but the iframe remains blank.
是从 gmail 下载的电子邮件。我还将上述路径保存在数据库中,以便稍后使用。现在我试图在 iframe 中显示这个 htm 文件,但它不起作用。用户单击电子邮件将他带到 read_email 页面,我试图在该页面上将上述路径分配给 iframe,但 iframe 保持空白。
emailMessage.Attributes.Add("src",commandReader["email_message_path"].ToString());
emailMessage is the name of iframe and commandReader is normal SqlDataReader which I am using to read the path of the file mentioned above and then assigning that path to src attribute of iframe, I have placed this code in page_load event.
emailMessage 是 iframe 的名称,commandReader 是普通的 SqlDataReader,我用它来读取上述文件的路径,然后将该路径分配给 iframe 的 src 属性,我已将此代码放在 page_load 事件中。
But as I said Iframe remains blank. Please help me out.
但正如我所说,Iframe 仍然是空白的。请帮帮我。
Thanks.
谢谢。
采纳答案by strnk
Local files are referenced with the file
URI scheme. If your email message path is only D:\Emails\...
then you'll have to prepend it with file://
:
使用file
URI 方案引用本地文件。如果您的电子邮件路径只有D:\Emails\...
那么您必须在它前面加上file://
:
file://D:\Emails\...
Note that most browser will prevent you from including a local filefrom a remote website!.
请注意,大多数浏览器会阻止您包含来自远程网站的本地文件!。
回答by user1469130
Have you tried putting file:///
before the path to the file?
Like file:///D:\Emails\GmailId1380ec660e0e656a\doc.htm
您是否尝试file:///
在文件路径之前放置?喜欢file:///D:\Emails\GmailId1380ec660e0e656a\doc.htm