TYPESCRIPT - Update css of iframe by jquery

From GUILLARD WIKI
Jump to navigation Jump to search

In your .ts file:

  private mainFunction(): void {
      this.waitForEl('#iframeABC', '.comment', 0, () => {
          $('#iframeABC').contents().find('.comment').css({
              'border-left': '0px',
              'border-right': '0px'
          });
          console.log('Updated css iframe');
      });
  }   

  private waitForEl(iframe: string, selector: string, count: number, callback: () => void): void {
    if ($(iframe).contents().find(selector).length > 0) {
      callback();
    } else {
      setTimeout(() => {
        count++;
        if (count <= 10) {
          this.waitForEl(iframe, selector, count, callback);
        } else {
          return;
        }
      }, 1000);
    }
  }