Run JQuery in the context of another frame

后端 未结 4 1330
孤独总比滥情好
孤独总比滥情好 2020-11-27 04:09

The client I am working with has a frameset like so...


  

        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 04:53

    The jQuery function, which you more commonly call with $, takes a second argument called context, which is "which DOM element of jQuery object should I do the search in". Most of the time you omit this argument, so the context defaults to the current HTML document. When your code is executing in the iframe, the document defaults to that iframe's document. But you can easily grab the document for one of the other frames.

    For example, put this in myFrame.html, and this will remove all the h1 elements from the frame with blah.html in it. Notice the second argument to $, which is the expression that grabs the blah frame from within important frame:

    
      
        
        
      
      
        

    My Frame

    Do It

提交回复
热议问题