我需要在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!
}
}
}])
ps我已经将jQuery链接放在主页顶部,在其他地方我也可以使用它!
与使用相似,document.ready
否则window.onload
您无法在加载iframe文档之前访问其内容。
link: function(scope, elem, attrs) {
elem.on('load', function(){
elem.contents().find('#element').html('change') ;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句