1

I have a page opened in iFrame. I want to refresh the page after x seconds (x could be any digit I get greater than 5). How I can do this?

here is my code;

<iframe sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts" class="iframe" ng-show="$ctrl.getFrameURL() !== 'Default URL'" ng-src="{{$ctrl.getFrameURL()}}" width="100%" height="100%" scrolling="yes" frameBorder="0" id="remotePageFrame"></iframe>

I have checked there are some questions on StackOverflow where guys reloaded the page by updating the scope. I do not want to update the scope as my URL value in scope variable remains the same. Is there anything in JavaScript or AngularJs which can help to refresh the page in an iframe.

Update-1

The solution suggested by @sarvon ks works for my own pages which are hosted within my project but it complains when I try to refresh any external/ third-party page. In my page, I have a loop over an iFrame which opens the mutiple page. Most of them are external pages. For the external pages, I get Uncaught SecurityError exception.

-- Uncaught SecurityError: Blocked a frame with origin "http://localhost:63342" from accessing a cross-origin frame.

This error is already well discussed in an existing question. Is there any other workaround to refresh page opened in iFrame?

Abdul Waheed
  • 365
  • 1
  • 3
  • 20

1 Answers1

0

check this code it will work


    var duration = 100;
    function reloadIframe() {
          var iframeDome = document.getElementsByTagName("iframe");
            iframeDome[0].contentWindow.location.reload();
    }

    setInterval(reloadIframe,duration);

    <iframe src="https://www.google.com"></iframe>
sarvon ks
  • 584
  • 2
  • 10
  • Thanks @sarvon ks. I have updated my question. The solution which you have provided works for same origin pages. Is there any way to reload the third party page? – Abdul Waheed May 13 '19 at 12:32