Search code examples
javascripthtmliframechrome-extension-manifest-v3

Google Chrome - Remove Class inside Iframe


How do I remove a class="js-action-group" from an Iframe after it fully loads?

<iframe src="https://000.maps.arcgis.com/apps/dashboards/000" style="width: 100%; height: 100%; border: 0"></iframe>

enter image description here


Solution

  • You cannot alter contents of an iframe that are loaded from a different domain. This is a restriction in place by browser security. if you are on same domain you can try this

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>contents demo</title>
      <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
    </head>
    <body>
     
    
    <iframe src="https://000.maps.arcgis.com/apps/dashboards/000" style="width: 100%; height: 100%; border: 0" id="frameDemo"></iframe>
     
    <script>
    $( "#frameDemo" ).contents().find( ".js-action-group" ).remove();
    </script>
     
    </body>
    </html>