How to change javascript context in jquery?

Viewed 226

When I call $(element).attr('class') when javascript context:top (chrome console), it's not working. When I change it to OffAmazonPaymentsWidgets1IFrame, it's working, beacause this element in an other iframe and have other html tag in this frame. How could I change javascript context?enter image description here

1 Answers

It may be because the iframe has extra set of restrictions due to the present of the sandbox attribute, such as not allowing javascript in the iframe.

"The sandbox attribute enables an extra set of restrictions for the content in the iframe.

When the sandbox attribute is present, and it will:

  • treat the content as being from a unique origin

  • block form submission

  • block script execution

  • disable APIs

  • prevent links from targeting other browsing contexts

  • prevent content from using plugins

  • prevent the content to navigate its top-level browsing context

  • block automatically triggered features (such as automatically playing a video or automatically focusing a form control)

The value of the sandbox attribute can either be just sandbox (then all restrictions are applied), or a space-separated list of pre-defined values that will REMOVE the particular restrictions."

Quoted from: https://www.w3schools.com/tags/att_iframe_sandbox.asp

You can try allowing script by setting the sandbox attribute in the iframe as below:

<iframe src="demo_iframe_sandbox_origin.htm" sandbox="allow-scripts"></iframe>

Quoted from: https://www.w3schools.com/tags/att_iframe_sandbox.asp

Related