Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7969383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:13:44+00:00 2026-06-04T07:13:44+00:00

// the iframe of the div I need to access var iframe = document.getElementsByTagName(iframe)[2];

  • 0
// the iframe of the div I need to access
var iframe = document.getElementsByTagName("iframe")[2];
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;

// resize 'player' in the iframe
innerDoc.getElementById('player').width = "1000px";
innerDoc.getElementById('player').height = "650px";

Running in a userscript for this url: http://www.free-tv-video-online.me/player/sockshare.php?id=24DA6EAA2561FD60

Why does Chrome come out with this error and fail the script?:

Unsafe JavaScript attempt to access frame with URL http://www.sockshare.com/embed/24DA6EAA2561FD60 
from frame with URL http://www.free-tv-video-online.me/player/sockshare.php?id=24DA6EAA2561FD60. 
Domains, protocols and ports must match.

(I’m only a basic Javascript user)


Final code, many thanks to the answerer:

// ==UserScript==
// @name       Resize
// @include    http://www.free-tv-video-online.me/player/sockshare.php*
// @include    http://www.sockshare.com/*
// ==/UserScript==

if (!(window.top === window.self)) {
    var player = document.getElementById('player');
    setSize(player);
}

function setSize(player) {
    player.style.setProperty("width", "1000px");
    player.style.setProperty("height", "650px");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:13:45+00:00Added an answer on June 4, 2026 at 7:13 am

    It’s true that ordinary javascript cannot access iframe content, that’s on a different domain, for security reasons. However, this by no means stops userscripts in Chrome, Tampermonkey or Greasemonkey.

    You can process iframed content in a userscript because Chrome (and Firefox) process iframe’d pages just as if they were the main page. Accounting for that, scripting such pages is a snap.

    For example, suppose you have this page at domain_A.com:

    <html>
    <body>
        <iframe src="http://domain_B.com/SomePage.htm"></iframe>
    </body>
    </html>
    

    If you set your @match directives like this:

    // @match http://domain_A.com/*
    // @match http://domain_B.com/*
    

    Then your script will run twice — once on the main page and once on the iframe as though it were a standalone page.

    So if your script was like this:

    // ==UserScript==
    // @name  _Test iFrame processing in Chrome and Tampermonkey
    // @match http://domain_A.com/*
    // @match http://domain_B.com/*
    // ==/UserScript==
    
    if (/domain_A\.com/i.test (document.location.href) ) {
        //Main page
        document.body.style.setProperty ("background", "lime", "important");
    }
    else {
        //iFrame
        document.body.style.setProperty ("background", "pink", "important");
    }
    

    You would see the main page in lime-green, and the iframed page in pink.

    Alternatively, you can test like this:

    if (window.top === window.self) {
        //--- Code to run when page is the main site...
    }
    else {
        //--- Code to run when page is in an iframe...
    }
    



    As you discovered (per comment on another answer), you can disable the same origin policy on Chrome. Don’t do this! You will leave yourself open to all kinds of shenanigans set up by bad people. In addition to evil sites, many nominally “good” sites — that allow users to post content — could potentially track, hack, or spoof you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to output a DIV width into a URL for an iframe but
So basically I have something like this <div class=iframe-holder> <span></span> <iframe src=iframe.html width=200 height=200
I'm building a wysiwyg-editor with an editable iframe using document.execCommand() . Now i need
I need to access a value within a form and an iframe from the
I need to wrap an iFrame in a div wihtout the iFrame reloading the
I need to access an id found inside an iframe. I have the following
I need to insert an iframe into a div using javascript. I need this
I create a iframe in a div by jQuery.Then I load another page(lets say
So I have a Div containing an iframe that I can Clone using JQuery.
<div> <iframe id=cq-cf-frame > <iframe id=gen367> <body spellcheck=false id=CQrte style=height: 255px; font-size: 12px; font-family:tahoma,arial,helvetica,sans-serif;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.