Accessing an iframe document (contentWindow) - JavaScript Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ธ.ค. 2024

ความคิดเห็น • 97

  • @dcode-software
    @dcode-software  2 ปีที่แล้ว +1

    *RELATED VIDEO: SEND DATA BETWEEN TABS IN JAVASCRIPT*
    th-cam.com/video/wYcvzLFHFN0/w-d-xo.html
    🏷 *THE ULTIMATE JAVASCRIPT DOM CRASH COURSE* 👇
    www.udemy.com/course/the-ultimate-javascript-dom-crash-course/?referralCode=DC343E5C8ED163F337E1

    • @CodingMation
      @CodingMation 11 หลายเดือนก่อน

      Bro I literally too confusing how to change light mode to dark. Because I make a nav bar for every page and button who change mode but when I used then it not changed so I used this method to send data I thought that it's work with local storage data without reload website.

  • @christianhelwig
    @christianhelwig 3 ปีที่แล้ว +5

    Thank you!!! You helped me figure something out I was working on for four hours. This enabled me to understand multiple codes I was working with. Thank you!

  • @TECHINSPEC
    @TECHINSPEC 4 ปีที่แล้ว +29

    This is for the Same-origin Iframe only... You can't access from the different domain using the method explained in this video

    • @saurabhkum2050
      @saurabhkum2050 3 ปีที่แล้ว +7

      Is there any way to do the same for different domains ?

    • @marcelo.victor
      @marcelo.victor 2 ปีที่แล้ว +1

      Just use postMessage with all origins (*) and event listener to receive the message and you are all set.

    • @badmuskaybee5111
      @badmuskaybee5111 2 ปีที่แล้ว

      @@marcelo.victor Can you clarify
      ?

    • @marcelo.victor
      @marcelo.victor 2 ปีที่แล้ว +2

      @@badmuskaybee5111 on the child you add a event listener on page load to get this page height (document.body.scrollHeight) and pass it via postMessage (accepting all URL origins using * in message) to the parent page, that have a script with a window event listener to get that message and then apply that height passed to the style.

  • @p1xe2
    @p1xe2 4 ปีที่แล้ว

    This channel has solution for almost every problem

    • @Hangoutapp
      @Hangoutapp 3 ปีที่แล้ว

      An that's why I love the channel

  • @heatvisuals
    @heatvisuals 5 ปีที่แล้ว +9

    I like the typing sound effects. Sounds real af

    • @rezaz7167
      @rezaz7167 4 ปีที่แล้ว +3

      it might be real, I think its a mechanical keyboard

    • @_.sunnyraj._
      @_.sunnyraj._ 4 ปีที่แล้ว +1

      Fool

  • @arvy10
    @arvy10 18 วันที่ผ่านมา +1

    When we include the in the webpage in the middle of the page on hitting in and loading the website the website directly goes to the portion any solutions ,?

  • @omarzaky646
    @omarzaky646 3 ปีที่แล้ว

    You are the best javascript programmer in the world. Thank you very much 🌹

  • @Tmmy22
    @Tmmy22 2 ปีที่แล้ว +9

    What if the origin of the is at a different origin, i.e. not local to the page? Is something similar possible that yeilds the same outcomes?

  • @leopoldosantiago7027
    @leopoldosantiago7027 3 ปีที่แล้ว +6

    Meu amigo gringo, muito obrigado! Sua solução é simples e fácil de implantar. Parabéns!

  • @hessiride1729
    @hessiride1729 3 ปีที่แล้ว +7

    This example shows that will only work for local pages however if you link the to another link it will be dom exception for x-frame error

  • @valentinagajic7559
    @valentinagajic7559 4 ปีที่แล้ว +16

    This is ok, when pages are from same source,but how to do that if we embed in some other website? Can we manipulating with objects of that?

    • @guilhermezanetti1046
      @guilhermezanetti1046 4 ปีที่แล้ว +1

      how?

    • @pradeepkumarrana5651
      @pradeepkumarrana5651 4 ปีที่แล้ว

      Anyone Reply?

    • @abh1yan
      @abh1yan 4 ปีที่แล้ว

      @@pradeepkumarrana5651 it's not possible

    • @Snoo29293
      @Snoo29293 3 ปีที่แล้ว

      There is the pointer-events CSS property you can use, however, when used, the s are ignored by all the mouse events, meaning your window mousemove events will be detected even when hovered over the , but you will not be able to interact with the anymore, this isn't the perfect solution, but in certain situations this may be just good enough to solve your problems, if you want for example to be able to drag an element around your page and want to prevent s from canceling your mousemove event you can change the pointer-events property for s every time the element is being dragged and change it back after it is dropped.

    • @kirua_h
      @kirua_h 3 ปีที่แล้ว

      This is not working for me. Its saying "blocked a frame with origin null from accessing a cross origin frame" even though both the files are in the same folder

  • @murtazamohammadi9370
    @murtazamohammadi9370 2 ปีที่แล้ว +1

    I have one question about Iframe: I displayed an external website in my angular project, inside external website I have a link to open pdf. if I click on that link, it will be opened in a new tab. I want to open it inside the . how can I do that. I would be very happy hearing back from you thanks

  • @arnab1prince
    @arnab1prince 4 ปีที่แล้ว +1

    Perfect, to the point video.. Thanks

  • @mr.c7411
    @mr.c7411 4 ปีที่แล้ว

    Great video man

  • @celsoferreira8625
    @celsoferreira8625 ปีที่แล้ว

    Thanks man. That´s great.

  • @vicente5907
    @vicente5907 5 ปีที่แล้ว +1

    Hello, tnx for this video is very helpful. I just want to ask if is possible to do the same staff but with the button inside the ? for example i want to push the button and then close the do a z-index in order to hidde it.
    Kind regards.

  • @wowwwww1993
    @wowwwww1993 3 ปีที่แล้ว +5

    Thank you for this great video. Can you post a version with an onload-execution? As soon as the script is loaded, some JS-code should be executed.

  • @Oxanka19
    @Oxanka19 หลายเดือนก่อน

    How to do animation, when external request in frame is firstly small, centered and on click it is as big as request (on click it gets bigger)

  • @michaelcrossley4716
    @michaelcrossley4716 ปีที่แล้ว

    big help! Thanks.

  • @cmtg4471
    @cmtg4471 3 ปีที่แล้ว

    Nice content by the way

  • @vd-bro9985
    @vd-bro9985 2 ปีที่แล้ว

    great video

  • @manjindersingh-gj4ww
    @manjindersingh-gj4ww 5 ปีที่แล้ว

    Best one I found

  • @vicente5907
    @vicente5907 5 ปีที่แล้ว +1

    Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
    i get this error when i do a console.log(myIframe)

    • @forallah7615
      @forallah7615 4 ปีที่แล้ว

      I had the same error ..Take a look at this :
      stackoverflow.com/questions/29983786/blocked-a-frame-of-origin-null-from-accessing-a-cross-origin-frame-chrome

    • @TECHINSPEC
      @TECHINSPEC 4 ปีที่แล้ว

      This is for the Same-origin Iframe only... You can't access from different domain using the method explained in this video

  • @franktorrejonhuarcaya4370
    @franktorrejonhuarcaya4370 4 ปีที่แล้ว

    Thank you! it was very helpful.

  • @ilyaklimov3135
    @ilyaklimov3135 4 ปีที่แล้ว +1

    Thank you!

  • @bikramchettri9405
    @bikramchettri9405 5 ปีที่แล้ว +2

    Can you show how to use scrollHeight properties of an element?

  • @thelostman5625
    @thelostman5625 2 ปีที่แล้ว

    *Question:*
    How can I open external application (on mobile) using JavaScript (create open-in-app feature)?

  • @shashikantvaidya5252
    @shashikantvaidya5252 4 ปีที่แล้ว +1

    Hello sir my question is i have Iframe and inside i have Pdf file i want to get the position of Scroll bar of how to get

    • @vmars316
      @vmars316 3 ปีที่แล้ว

      Sounds interesting , can you share your code , Thanks

  • @vicovdeventuin
    @vicovdeventuin 5 ปีที่แล้ว

    Thanks! Is it also possible to pause and start an embedded video from youtube that is running in an iFrame?

    • @kevinb6568
      @kevinb6568 3 ปีที่แล้ว +1

      Yes it is. For example:

    • @keppu2661
      @keppu2661 2 ปีที่แล้ว

      @@kevinb6568 is it also possible to use this one on video widgets of elementor?

  • @colindante5164
    @colindante5164 3 ปีที่แล้ว

    Awesome!!!! Thankyou much)))

  • @nishilsuthar2749
    @nishilsuthar2749 7 หลายเดือนก่อน

    But what can I do this if the component is comming from another origin

  • @stig6339
    @stig6339 7 หลายเดือนก่อน

    how do i change the file inside an to another at runtime

  • @vmars316
    @vmars316 3 ปีที่แล้ว

    Do I need the .css to make it run error free ?
    const Document = myIframe.contentDocument;
    Why does this statemment retern null ?:
    console.log(Document) // ? = null
    WHy does this starement give me this error:
    Uncaught TypeError: Cannot read property 'querySelector' of null
    Document.body.style.backgroundColor = lightgreen ;
    I have typed out your code many times , but it always gives errors .
    Can I get a copy of the source code .
    Thanks

  • @rezaz7167
    @rezaz7167 4 ปีที่แล้ว +3

    .contentDocument is null, do you guys know why ?

    • @vmars316
      @vmars316 3 ปีที่แล้ว

      Ya me too !

  • @zqgAFf
    @zqgAFf 2 ปีที่แล้ว

    I am a bit curious how to get the console content from this and show it somewhere else in the web browser not in the developer tools

  • @user-888azim-97
    @user-888azim-97 3 ปีที่แล้ว +1

    could you also make video for embed pls?

  • @raymytech
    @raymytech 3 ปีที่แล้ว

    How can I load a specific table or div only from another website?

  • @kaushalsiriguppa38
    @kaushalsiriguppa38 หลายเดือนก่อน

    How to add eventlisteners to ?

  • @skimran22
    @skimran22 5 ปีที่แล้ว +1

    Thanks it’s very helpful

  • @zakimdh1070
    @zakimdh1070 3 ปีที่แล้ว

    Hello , can you make popup work inside box

  • @satishganai3942
    @satishganai3942 5 ปีที่แล้ว +1

    how to access cross-origin external website like google.com inside . I am getting cross-origin error. Please help

    • @dcode-software
      @dcode-software  5 ปีที่แล้ว +1

      It's not an error, it's a restriction. Looks like Google doesn't want people embedding their website in an IFrame. Google has requested this and Chrome is obliging

    • @vicente5907
      @vicente5907 5 ปีที่แล้ว +1

      @@dcode-software fak google!

  • @nyctophillia2292
    @nyctophillia2292 2 ปีที่แล้ว

    why is the nested document not listening to events?

  • @abusalahamusazangi6507
    @abusalahamusazangi6507 ปีที่แล้ว

    How to insert a script within a head tag of an iFrame if the iFrame has no id attributes?

  • @amatuluzma3828
    @amatuluzma3828 3 ปีที่แล้ว

    can I save content to database and then retrieve it?

  • @buenito
    @buenito 4 ปีที่แล้ว

    problem in ie8, you solved?

  • @leandrmiklashevich297
    @leandrmiklashevich297 4 ปีที่แล้ว

    Ok. I have this situation:
    I have a page with (same origin). I make a click on a button within . How to handle it in my parent page? How to send some kind of data from to parent page? Thank you.

    • @justluthra
      @justluthra 4 ปีที่แล้ว

      if you founded solution then please help me, I am stuck on same problem

  • @vivianeasaraiva80
    @vivianeasaraiva80 9 หลายเดือนก่อน

    Hi, please could you do a video showing how to use Javascript to change content inside every 5s? That would be very helpfull

  • @kedarsatwik6938
    @kedarsatwik6938 3 ปีที่แล้ว

    hello, video is very nice and useful,
    I have a button inside , and nav bar ouside , how can we write a function so that when we click button nav bar should disappear

  • @thefreshweb
    @thefreshweb 4 ปีที่แล้ว

    thank you very much, very much, very much ❤️💖💜💙

  • @ramureddy2500
    @ramureddy2500 4 ปีที่แล้ว

    it is posible Accessing an document in angualr 6 ?

  • @TBrianOnline
    @TBrianOnline ปีที่แล้ว

    Now please make it to work in React, which has a different dynamic of loading window.

  • @bsk8643
    @bsk8643 2 ปีที่แล้ว

    Can you tell how to handle in case of below html...
    #document

    #document
    .....and so on...
    In this case how do I find a specific elemrnt in nth document inside nth ?
    Can you please reproduce this and help me to understand 🙏

  • @mohammedhissham8719
    @mohammedhissham8719 4 ปีที่แล้ว

    wht if button is in another

  • @buddyvikas9285
    @buddyvikas9285 3 ปีที่แล้ว

    Sir can you please tell me how to prevent to make browser history?

  • @mdridoy-ef2pw
    @mdridoy-ef2pw 2 ปีที่แล้ว

    I have a textarea and an .
    I want whatever user types in the textarea to be executed inside the as a script.
    for example if user types console.log('hello world'), I want this code to be executed inside the as a script.
    Is there any way to do it.
    Maybe adding the text as a script inside the or something?

  • @daniels3401
    @daniels3401 4 ปีที่แล้ว

    I think I know the answer to this already but theres not any way to actually do this cross origin is there? All my leads are telling me no

  • @staceyloulouse
    @staceyloulouse 3 ปีที่แล้ว

    seems life it would be more efficient to use the target attribute to place an , but thanks for sharing.

  • @BilalHassan-wm5ev
    @BilalHassan-wm5ev 3 ปีที่แล้ว

    hoe to remove div from ?

  • @rooiboquality6603
    @rooiboquality6603 4 ปีที่แล้ว

    Can you post the source code somewhere?

    • @vmars316
      @vmars316 3 ปีที่แล้ว

      AMEN

  •  4 ปีที่แล้ว

    nice

  • @igu642
    @igu642 7 หลายเดือนก่อน

    ❤❤

  • @ashutoshmehere5915
    @ashutoshmehere5915 4 ปีที่แล้ว

    Content security police error sir

  • @rodrigogomescordeiro1616
    @rodrigogomescordeiro1616 2 ปีที่แล้ว

    MUITO BOM

  • @kushkumar2878
    @kushkumar2878 5 ปีที่แล้ว

    I am getting below error while accessing the with its id
    SecurityError: Permission denied to access property "document" on cross-origin object

    • @dcode-software
      @dcode-software  5 ปีที่แล้ว

      You need to make sure the IFrame URL comes from the same origin as the site that has the IFrame

    • @ozsuakin
      @ozsuakin 5 ปีที่แล้ว +1

      @@dcode-software what about working with chrome extension?

    • @YousefTrad
      @YousefTrad 3 ปีที่แล้ว

      @@ozsuakin dam, this was my same question...did you figure it out?

  • @davidroddini1512
    @davidroddini1512 3 ปีที่แล้ว +1

    0:04 “My name is dumb”
    Did he say dumb? Don’t be so hard on yourself dude. I am sure your name is not that bad.

  • @varunvc532
    @varunvc532 3 ปีที่แล้ว

    guy's name is DOM damn