Javascript Meteor.js安全嵌入iframe
我有一个meteor.js应用程序,其中包含聊天。我们需要允许用户从youtube和soundcloud发布嵌入代码。安全地 我使用djedi:sanitize html客户端来清理用户输入,而不是包含“youtube”和“soundcloud.com”的输入 所以,对于YouTube,我以用户输入字符串为例,让它工作Javascript Meteor.js安全嵌入iframe,javascript,regex,iframe,meteor,embed,Javascript,Regex,Iframe,Meteor,Embed,我有一个meteor.js应用程序,其中包含聊天。我们需要允许用户从youtube和soundcloud发布嵌入代码。安全地 我使用djedi:sanitize html客户端来清理用户输入,而不是包含“youtube”和“soundcloud.com”的输入 所以,对于YouTube,我以用户输入字符串为例,让它工作 您可以使用以下JS代码: var getHostname = function(href) { var l = document.createElement("a");
您可以使用以下JS代码:
var getHostname = function(href) {
var l = document.createElement("a");
l.href = href;
return l.hostname;
};
并在代码中使用它:
getHostname("https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/227010461&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&visual=true")
返回:
“w.soundcloud.com”
谢谢你的正则表达式,但我需要两个URL,因为我需要曲目ID。@FloridaGard对不起,我不明白你的意思