Jquery 在Angularjs中更改iframed页面的内容
我需要在AngularJS中动态构建各种html页面,然后更改它们的部分html内容。我已经创建了一个指令,它的iFrame很好,但我的问题是,我不能像jQuery那样访问iFrame页面的内容!我也不能使用jqLite!有人能帮忙吗 下面是指令的样子Jquery 在Angularjs中更改iframed页面的内容,jquery,angularjs,iframe,angularjs-directive,jqlite,Jquery,Angularjs,Iframe,Angularjs Directive,Jqlite,我需要在AngularJS中动态构建各种html页面,然后更改它们的部分html内容。我已经创建了一个指令,它的iFrame很好,但我的问题是,我不能像jQuery那样访问iFrame页面的内容!我也不能使用jqLite!有人能帮忙吗 下面是指令的样子 myApp.directive('pageiframe', ['$scope','$location', function($scope,$location) { var src= some URL // I get this some
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!
}
}
}])
myApp.directive('pageiframe',['$scope','$location',函数($scope,$location){
var src=某个URL//
返回{
限制:“C”,
替换:正确,
模板:“”,
链接:功能(范围、要素、属性){
var targetIframe=elem[0]//这里我们得到了iframe,但是我无法更改它的html内容
elem.contents().find('#element').html('change')//这不起作用!
}
}
}])
p、 我已经将jQuery链接放在主页的顶部,在其他地方我可以很好地使用它 类似于使用
document.ready
或window.onload
在iframe文档加载之前,您无法访问其内容
link: function(scope, elem, attrs) {
elem.on('load', function(){
elem.contents().find('#element').html('change') ;
}
}