Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Incorrect information regarding access to thedocument of theiframe#3559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Alexandre887 wants to merge1 commit intojavascript-tutorial:master
base:master
Choose a base branch
Loading
fromAlexandre887:master-17

Conversation

Alexandre887
Copy link
Member

Cross-window communication

Code:

<script>  iframe.onload = function(){// we can get the reference to the inner windowletiframeWindow=iframe.contentWindow;// OKtry{// ...but not to the document inside itlet doc=iframe.contentDocument;// ERROR // 🟢}catch(e){alert(e);// Security Error (another origin)}// also we can't READ the URL of the page in iframetry{// Can't read URL from the Location objectlethref=iframe.contentWindow.location.href;// ERROR}catch(e){alert(e);// Security Error}// ...we can WRITE into location (and thus load something else into the iframe)!iframe.contentWindow.location='/';// OKiframe.onload=null;// clear the handler, not to run it after the location change};</script>

In the line labeled🟢, we will not get any error when trying to accessiframe.contentDocument.

MDN:HTMLIFrameElement: contentDocument property:

If the iframe and the iframe's parent document areSame Origin, returns aDocument (that is, the active document in the inline frame's nested browsing context),$\Huge\textcolor{red}{else}$$\Huge\textcolor{red}{returns}$$\Huge\textcolor{red}{null}$.

@smith558smith558 self-assigned thisFeb 14, 2024
@smith558smith558 added the P1High priority labelFeb 14, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees

@smith558smith558

Labels
P1High priority
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Alexandre887@smith558

[8]ページ先頭

©2009-2025 Movatter.jp