javascript - 使用javascript从变量中的iframe获取src宽度和高度

标签 javascript regex iframe

希望有人能在这里帮助我。 我有一个带有 iframe 的变量,就像这样。

var iframe = '<iframe src="http://someaddress.com" width="600" height="500"></iframe>';

我想从变量中获取 src、宽度和高度,并放入它们自己的变量中。我知道我可以对它使用正则表达式,但我不知道该怎么做。

最佳答案

var iframe = '<iframe src="http://someaddress.com" width="600" height="500"></iframe>',
    regEx = /(src|width|height)=["']([^"']*)["']/gi;

iframe.replace(regEx, function(all, type, value) {
    console.log(type); // src/width/height
    console.log(value); //url/600/500
});

关于javascript - 使用javascript从变量中的iframe获取src宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13380279/

相关文章:

regex - 正则表达式用于构建解析器吗?

javascript - 如何从 iframe 调用函数

html - IFrame 在 Safari 中不工作

javascript - 在 Electron 中使用 THREE.js 时,Web 开发工具消失

javascript - anchor 标记弹出一个 div 而不是一个新页面

正则表达式 4 个字符和 1 个空格最少的任何位置

javascript - Asp .net core如何加载html文件byte[]到iframe src View

javascript - 有没有办法将 Javascript 对象附加到选择选项

javascript - Div 样式未定义(Javascript)

c# - OrderedDictionary 和正则表达式