【发布时间】:2016-01-25 10:18:09
【问题描述】:
我需要在 AngularJS 中动态地 iframe 各种 html 页面,然后更改它们的部分 html 内容。我创建了一个指令,它的 iframe 很好,但我的问题是我不能像我们在 jQuery 中那样访问 iframed 页面的内容!我也不能使用 jqLite 这样做!任何人都可以帮忙吗?
这是指令的样子
myApp.directive('pageiframe', ['$scope','$location', function($scope,$location) {
var src= some URL // I get this somehow
return {
restrict: 'C',
replace: true,
template: "<iframe src="+src+" height='2000px' width='100%' frameborder='0'></iframe>",
link: function(scope, elem, attrs) {
var targetIframe=elem[0] // here we get the iframe but then i can't change its html content
elem.contents().find('#element').html('change') // this doesn't work!
}
}
}])
p.s 我已经把 jQuery 链接放在了主页的顶部,我可以在其他地方使用它!
【问题讨论】:
标签: jquery angularjs iframe angularjs-directive jqlite