将参数传递给iframe src

时间:2017-02-23 08:30:09

标签: javascript html html5 iframe src

我有两个代码块

首先:

function readJason() {
  var mainInfo = null;
  var _DATA_FOLDER = process.env.LOCALAPPDATA + '/dmv/dmv.data/cameraUrl.json';
  $http.get(_DATA_FOLDER).success(function(data) {
    mainInfo = data;
    var url = mainInfo.url;
    cameraDialog(url);
  });
}

现在url参数保留https://www.google.com,例如。

第二

function cameraDialog(url) {
  $mdDialog.show({
    template: `<md-dialog class="fullscreen-dialog" layout="column"><iframe src='url' scrolling="yes" frameborder="0" style="position: relative; height: 100%; width: 100%;">
            </iframe></md-dialog>`,
  })
}

如何将url参数插入src? (就像我这样做的方式错了)

感谢!

2 个答案:

答案 0 :(得分:1)

模板(ES6 / 2015):

{
    template: `<md-dialog class="fullscreen-dialog" layout="column"><iframe src='${url}' scrolling="yes" frameborder="0" style="position: relative; height: 100%; width: 100%;">
            </iframe></md-dialog>`,
  }

或者

模板(遗产):

{
    template: '<md-dialog class="fullscreen-dialog" layout="column"><iframe src="'+url+'" scrolling="yes" frameborder="0" style="position: relative; height: 100%; width: 100%;">
            </iframe></md-dialog>',
  }

答案 1 :(得分:0)

改为使用:

template: '<md-dialog class="fullscreen-dialog" layout="column"><iframe src="' + url + '" scrolling="yes" frameborder="0" style="position: relative; height: 100%; width: 100%;"></iframe></md-dialog>'