angularjs - How to refresh iframe url? -
i creating app using ionic in displaying url using iframe. html code:
<iframe id="myframe" width="100%" height={{iframeheight}}>
this angular js:
$scope.iframeheight = window.innerheight; document.getelementbyid("myframe").src = value['url'];
everything working, when make changes on site backend , refresh app new changes not appearing in app.
the thing doing in code not valid way of doing it. manipulating dom using native method not run digest cycle, need run manually doing $scope.$apply()
. solve problem should not dom manipulation controller considered bad practice. rather i'd suggest use angular 2 way binding feature. assign url in scope scope variable , add on iframe tag using ng-src="{{url}}"
src
url updated angular , url updated iframe
load content src
url in it.
html
<iframe id="myframe" width="100%" ng-src="{{url}}" height={{iframeheight}}>
code
$scope.url = "http://example.com"
as change scope variable in controller the src
of iframe gets change , iframe
reload content.
update
to solve caching issue need append current date time url every time make new url , won't cached browser. $scope.url = "http://example.com?dummyvar="+ (new date()).gettime()
using never harm current behavior, need append dummyvar
current time value unique.
$scope.url = "http://example.com?dummyvar="+ (new date()).gettime()
Comments
Post a Comment