我正在从第三方导入HTML片段并将其嵌入到我的Angular 7应用程序之外的某个占位符中.有一个链接从javascript:片段内部开始,unsafe:将由Angular 作为前缀,这会破坏其功能.
Angular 的DOMSanitizer似乎只提供绕过HTML字符串安全性的方法.但是,在下面的方法中,我只是读取DOM节点并将其附加到不同的目的地.所以我需要一个DOM节点的解决方案.
根据我的研究,插入的节点在appendChild调用后可以直接运行,但是在Angular添加之后几毫秒unsafe:.
如何绕过DOM节点的安全性?
private insertPart(componentImportLinkId: string, targetSelector: string): void {
try {
const linkElement: any = document.getElementById(componentImportLinkId);
const componentContent = linkElement.import;
const componentTemplate = componentContent.querySelector('template');
const importedComponentTemplateClone = document.importNode(componentTemplate.content, true);
const appendToElement = document.querySelector(targetSelector);
appendToElement.appendChild(importedComponentTemplateClone);
} catch (e) {
console.error(`PortalLayoutComponent.insertPart: Can not insert '${targetSelector}'`, e);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个带有延迟加载模块和路由的普通 Angular 10 应用程序。但是,我有一个特殊的要求需要满足。
在大多数页面上,我想通过<app-root>在 index.html 中嵌入元素来使用路由等初始化完整的应用程序——这是AppComponent. 另一方面,在某些页面上,不应该初始化完整的应用程序,而应该只初始化一个<header-search>我使用 @angular/elements(Web 组件)注册的特定组件。这也意味着在这种情况下,除了<header-search>初始化(如果它不是由<header-search>组件本身嵌入)之外,不应该发生路由,也不应该发生任何其他组件。
旁注只是为了让您了解用例的背景:在我正在构建的项目中,并非所有部分都与 Angular 解耦。一些页面使用 Twig/PHP 在后端呈现。但是我需要使用 Angular 构建的标题中的搜索功能也可以在这些页面上使用。这意味着我不会同时拥有完整的应用程序,只有HeaderSearchComponent在这种情况下。然而,在其他页面上,完整的应用程序将被初始化,包括HeaderSearchComponet,因此不需要使用 Web 组件单独嵌入 - 在这种情况下,
<app-root>元素就足够了。
我的想法在哪里使用角度元素将HeaderSearchComponent作为<header-search>自定义 Web 组件注册,例如:
@NgModule({
imports: [BrowserModule, FormsModule, SharedModule],
declarations: [AppComponent],
bootstrap: [AppComponent],
entryComponents: [HeaderSearchComponent]
})
export class AppModule implements DoBootstrap {
constructor(injector: Injector) {
const webComponent = createCustomElement(HeaderSearchComponent, {
injector
});
customElements.define("header-search", webComponent);
}
public ngDoBootstrap(): void {}
} …Run Code Online (Sandbox Code Playgroud) 我的服务器上有一个受保护的目录.在这个目录中,我上传了一个视频.现在,如果我在浏览器中在Android上请求此视频,它就像一个魅力.如果我在最新版本的iOS上请求此视频,则无法播放.
我已经尝试过访问该视频
http://username:password@myServer.com/myDirectory/myFile.mp4
Run Code Online (Sandbox Code Playgroud)
但这会在iOS浏览器中引发"网络钓鱼攻击".
我不想用HTML嵌入视频,我想直接播放它.如何通过iOS和htaccess保护来实现这一点?
非常感谢!
//编辑:我想确定,这个问题只是因为htaccess保护.iOS似乎在播放受保护的视频时遇到问题.
使用 PHPMyAdmin Designer 工具时,我看不到关系(连接每个外键关系的行)。外键属性获得与其他属性不同的图标,但缺少线路连接。我已经尝试打开/关闭“显示/隐藏关系”。
我错过了什么?
我想规范化表行.除了IE(用IE 11测试)之外,这就像魅力一样.
我已经创建了一个演示代码片段来演示这个问题:
$(function() {
$("table tbody tr span").each(function() {
var $this = $(this);
var $parent = $this.parent();
$this.replaceWith($this.html());
$parent[0].normalize();
});
});Run Code Online (Sandbox Code Playgroud)
<link href="https://cdn.jsdelivr.net/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>President</th>
<th>Birthplace</th>
</tr>
</thead>
<tbody>
<tr>
<td><span>Zach</span>ary Taylor</td>
<td>Barboursville, Virginia</td>
</tr>
</tbody>
</table>Run Code Online (Sandbox Code Playgroud)
这会将<span>元素替换为其内容.在此步骤之后,节点将如下所示:
然后,normalize()调用合并分割的文本节点.但是,在IE11中,文本节点仍然是分开的.
我无法看到任何问题.这个问题的原因是什么,可能是什么解决方案?
事实证明这是一个IE11错误,我填写了错误报告!
有这样的代码时:
$elements.filter(() => {
console.log(this); // will be the parent scope's "this"
});
Run Code Online (Sandbox Code Playgroud)
你无法获得应该过滤的元素.所以你需要使用一个普通的函数,比如:
$elements.filter(function(){
console.log($(this)); // will be the element to filter
});
Run Code Online (Sandbox Code Playgroud)
有没有其他方式而不是使用正常的功能?我知道你可以使用的点击事件event.currentTarget,但是没有事件参数filter.
javascript ×3
angular ×2
jquery ×2
.htaccess ×1
angular10 ×1
dom ×1
ecmascript-6 ×1
ios ×1
mp4 ×1
mysql ×1
normalize ×1
php ×1
phpmyadmin ×1
sanitization ×1
sanitize ×1
security ×1
video ×1