- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
每次我在 Google Chrome 中加载 MHT 时,都会收到以下错误:
Blocked script execution in 'file:///C:/...' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.
我知道 allow-scripts
是 iframe
的 sandbox
属性的一个值,所以我不能将它的值设置为allow-scripts
,因为顶层框架似乎是一个内部框架。并且这个内部框架只添加了sandbox
属性,当使用file:///
加载文件时。 有没有办法让脚本在不使用 http://
的情况下运行?
我还尝试在开发工具的设置中取消选中禁用 JavaScript,但是这个复选框是灰色的。
最佳答案
在具有这种结构的 mhtml 文件的基础上:
MIME-Version: 1.0
Content-Type: multipart/related; boundary="----=_NextPart_EXSTREAMHTML"; type="text/html"
This is a multi-part message in MIME format.
------=_NextPart_EXSTREAMHTML
Content-Type: image/jpg
Content-Transfer-Encoding: base64
Content-Location: file:///HTMLImage1.jpg
...............................
------=_NextPart_EXSTREAMHTML
Content-Type: text/css; charset="us-ascii"
Content-Location: file:///CSS1.css
...............................
您可以使用类似的脚本从 mhtml 创建 html 并打开一个新窗口:
var w = window.open(URL,"popUpWindow_","width=650,height=450,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,location=no,directories=no,status=no");
w.document.write(getContentFromMHTML(mhtmlFileContent));
w.document.close();
/**
* Getting the html content and css + img in base of MHTML parameter.
* @param strMHTML
* @return
*/
function getContentFromMHTML(strMHTML){
//setting the bundary. For default is "------=_NextPart_EXSTREAMHTML"
var boundary_text = "------=_NextPart_EXSTREAMHTML";
var boundary_index = strMHTML.indexOf("boundary=\"");
if (boundary_index!=-1) boundary_text = "--" + strMHTML.substring(boundary_index + 10, strMHTML.indexOf("\";", boundary_index + 10));
//Setting the html and css content
var returnHTML = setHTMLAndCSSFromMHTML(strMHTML, boundary_text);
//Setting the img content to all img-src
returnHTML = setImgFromMHTML(returnHTML, strMHTML, boundary_text);
return returnHTML;
}
/**
* Get the html content.<br>
* Extract and add the css files in style tags to head.<br>
* Finally, add the final content to popUp
* @param strMHTML
* @param boundary_text
* @return
*/
function setHTMLAndCSSFromMHTML(strMHTML, boundary_text){
//begin tags
var tag_begin_doc = "<!DOCTYPE HTML";
var tag_begin = "<html>";
var tag_begin_upper = "<HTML>";
//end tags
var tag_end = "</html>";
var tag_end_upper = "</HTML>";
//getting the start of html content
var begin = strMHTML.indexOf(tag_begin_doc);
if(begin==-1) begin = strMHTML.indexOf(tag_begin);
if(begin==-1) begin = strMHTML.indexOf(tag_begin_upper);
//getting the end of html content
var end = strMHTML.indexOf(tag_end);
if(end==-1) end = strMHTML.indexOf(tag_end_upper);
//getting the html content
var final_str = strMHTML.substring(begin, end) + tag_end;
//Is necessary add the css before to add the html content to popUp
var strHTML = setCssFromMHTML(final_str, boundary_text, strMHTML);
return strHTML;
}
/**
* Extract the css content from MHTML and push as style tags.
* @param strHTMLtext
* @param boundary_text
* @param strMHTML
* @return
*/
function setCssFromMHTML(strHTMLtext, boundary_text, strMHTML) {
var begin_content_text = boundary_text;
var content_type_text = "Content-Type: text/css";
//getting the first index of contents
var begin_content_index = strMHTML.indexOf(begin_content_text);
//while exists a contents we must process all parts of mhtml
while(begin_content_index!=-1){
//getting the final index of current content
var end_content_index = strMHTML.indexOf(begin_content_text, begin_content_index + begin_content_text.length);
if (end_content_index==-1) end_content_index = strMHTML.length;
//getting the current content
var current_content = strMHTML.substring(begin_content_index, end_content_index);
//getting the indexes
var content_type_index = current_content.indexOf(content_type_text);
//Check that content is css
if (content_type_index!=-1) {
//getting the css in content (eg. p { margin-top: 0; margin-bottom: 0 }...)
var css_content = current_content.substring(current_content.indexOf(".css") + 4, end_content_index);
//Getting the index of tag head of the html content
var head_index = strHTMLtext.indexOf("</head>");
if (head_index==-1) head_index = strHTMLtext.indexOf("</HEAD>");
//Getting the html to head end tag
var head_begin = strHTMLtext.substring(0, head_index);
//Getting the html later of head end tag
var head_body = strHTMLtext.substring(head_index, strHTMLtext.length);
//Adding the css to end of head of html
var strHTMLtext = "";
if (css_content.indexOf("<style>")==-1 && css_content.indexOf("<STYLE>")==-1){
strHTMLtext = head_begin + "<style>" + css_content + "</style>" + head_body;
} else {
strHTMLtext = head_begin + css_content + head_body;
}
}
//getting the next index of contents
begin_content_index = strMHTML.indexOf(begin_content_text, end_content_index);
}
return strHTMLtext;
}
/**
* Find all images from MHTML and add to HTML content.
* @param strMHTML
* @param boundary_text
* @return
*/
function setImgFromMHTML(returnHTML, strMHTML, boundary_text){
var begin_content_text = boundary_text;
var content_type_text = "Content-Type: ";
var context_encoding_text = "Content-Transfer-Encoding: ";
var content_location_text = "Content-Location: ";
//getting the first index of contents
var begin_content_index = strMHTML.indexOf(begin_content_text);
//while exists a contents we must process all parts of mhtml
while(begin_content_index!=-1){
//getting the final index of current content
var end_content_index = strMHTML.indexOf(begin_content_text, begin_content_index + begin_content_text.length);
if (end_content_index==-1) end_content_index = strMHTML.length;
//getting the current content
var current_content = strMHTML.substring(begin_content_index, end_content_index);
//checking that content contains the all necessary data
if (current_content.indexOf(content_type_text) != -1 &&
current_content.indexOf(context_encoding_text) != -1 &&
current_content.indexOf(content_location_text) != -1) {
//getting the indexes
var content_type_index = current_content.indexOf(content_type_text);
var context_encoding_index = current_content.indexOf(context_encoding_text);
var content_location_index = current_content.indexOf(content_location_text);
//getting the context type (eg. image/jpg)
var context_type = current_content.substring(content_type_index + content_type_text.length , context_encoding_index);
//Check if the content is a image
if (context_type.indexOf("image/")!=-1) {
//getting the context encoding (eg. base64)
var context_encoding = current_content.substring(context_encoding_index + context_encoding_text.length, content_location_index);
//getting the content location (eg. file:///HTMLImage1.jpg)
var content_location = current_content.substring(content_location_index + content_location_text.length,
current_content.indexOf(".", content_location_index) + 4);
//getting the image name (eg. HTMLImage1.jpg)
var img_name = content_location.substring(content_location.lastIndexOf("/")+1, content_location.length);
//getting the image in base64 (eg. /9j/4AAQSkZJRgABAgEBLAEsAAD...)
var image_content = current_content.substring(current_content.indexOf(img_name) + img_name.length,
end_content_index);
//image_content = image_content.replace(/( |\n|\r)/g, "");
//creating the image src (eg. data:image/jpg;base64,/9j/4AAQSkZJRgABAgEBLAEsAAD...))
var textContent = "src=\"data:" + context_type + ";" + context_encoding + "," + image_content;
//replace the src in the image
returnHTML = returnHTML.replace("src=\""+img_name, textContent);
}
}
//getting the next index of contents
begin_content_index = strMHTML.indexOf(begin_content_text, end_content_index);
}
return returnHTML;
}
//
问候,
关于javascript - 为 .mht 文件启用脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27986868/
是否可以绕过“另存为”对话框来保存任何类型的文件?使用 WebBrowser 类 WebBrowser.ShowSaveAsDialog(); WebBrowser 控件中加载的内容是否可序列化以便保
我有一个 mht 文件,其中包含图像和一些文本。当我用 Notepad++ 打开它时,我看到 xml,然后看到难以辨认的文本,我认为这些文本是图像。有人可以告诉我如何使用 java 程序从 mht 文
MHT 文件的内容类型是什么? 最佳答案 微软作为 MHT 规范的共同作者,似乎认为它应该是 this support page 上的“message/rfc822” . 规范中似乎没有给出特定的 M
有人知道在 .NET 中使用 MHT 文件 ( Multi-Part MIME files ) 的库吗?我需要以编程方式从包含 Flash 网站的现有 MHT 文件中提取内容。我找不到任何此类库。 此
我有一个 mht 文件,我想得到 mht 的所有文本。我很难使用正则表达式,但我在 mht 中有除英语以外的其他语言,所以文本本身包含类似 A7=A98=D6 的内容... 选择在浏览器中查看的文件的
每次我在 Google Chrome 中加载 MHT 时,都会收到以下错误: Blocked script execution in 'file:///C:/...' because the docu
所以我有一套报告,当您选择顶部的按钮时,它会移动到由 jQuery 运行的新报告。这些报告中的每一个都是 iFramed 中的。我想将 MHT 文件 iFrame 到套件中,但是当我选择其中包含 MH
有人知道如何在 C# 中以编程方式生成 .mht 文件吗?在里面嵌入图像?问题是我已经意识到 .mht 文件能够在其中嵌入图像,而这种嵌入的图像当您更改其位置时,它会随整个文件 (mht) 一起移动。
我的客户目前正在使用 MHT 文件来存储浏览网页的离线表示。文件被保存并稍后在 Internet Explorer 中查看。 在查看文件时,我们希望确保绝对没有原始站点或任何其他站点的网络事件 - 内
使用以下函数表示从本地 html 文件生成 Web 存档 function TLessonConstructor2.CreateMHT( const FileName : string):boolea
我用它在网络浏览器中打开保存的离线 .mht 页面文件
我在 cognos 中生成了一些事件报告。然后我在 Cognos 中使用 JQuery 得到了这个动态报告: http://www.ibm.com/developerworks/library/ba-
我的磁盘中有一个 htm 页面 (C:\pages\page1.htm)。 此页面链接 CSS 和 gif (C:\pages\img\img1.gif, c:\pages\css\css1.css)
我有一个从 HTML 文件中提取信息的 C# 模块。但我的输入是一个 MHT 文件。如何只提取 MHT 文件的 html 部分? 最佳答案 我尝试了几种工具和库,据说这些工具和库允许我提取 MHT 的
我正在尝试将外部 mhtml 资源添加到 css。我有一个这样的 css 条目: *background-image: url(mhtml:file://C:/folder/base64.mht!im
我有一个“.mht”文件,我需要在浏览器中打开它,例如 View 或类似的东西。在我的 Controller 中,我返回一个带有 contentType 的 FilePathResult。但是,当我键
我想用 scala 来解析一个 .mht 文件,但我发现我的代码和 Java 完全一样。 以下是一个mht文件示例: From: Subject: Tencent IM Message MIME-V
当我需要编辑 .mht 文件时(例如:向站点添加一些文本),我遇到了这种情况。 您能否建议一种编辑 .mht(网络存档)文件的方法? 我尝试过的: (编辑器如:记事本、word); I-Explore
有没有人有任何示例代码发送MHT在 C# 中使用 SmtpClient 和 MailMessage? 我找到了关于使用 Alternate Views 的引人入胜的引用资料但我不知道如何使用我的 SS
我正在尝试使用 Jsoup(版本:1.7.3)解析 MHT 文档。目标是打开两个文件并将它们合并在一起(连接头部和主体)以获得一个完整的文件。但首先我在解析 mht 文件时遇到了问题,因为解析的结果有
我是一名优秀的程序员,十分优秀!