2

I need to use Bookmarklet to change the settings on some sites in its context. I have necessary var, but I dunno with help of which command to change selecting execution context.

Example

Which commands do use to change necessary var?

I checked:

  1. Select frame context with JavaScript
  2. Debugging iframes with Chrome developer tools
  3. what is the jQuery / JavaScript context of a frame within an iframe?
  4. Is there a way to change context to iframe in JavaScript console?

But this not help me

surfmuggle
  • 5,527
  • 7
  • 48
  • 77
YuuToso
  • 21
  • 1
  • 4

1 Answers1

3

hi if you want to select element with id test2 you can use document.getElementById('test2') need to wrap test2 with quotes

and if element with id test2 is inside iframe you need to select iframe first and cal contentDocument

var iframe = document.getElementById('iframe-id');
iframe.contentDocument.getElementById('test2');

or if you are testing with chrome devtools you can change context and use document.getElementById('test2') as normal

enter image description here

raksa
  • 898
  • 6
  • 17
  • Thanks. But sadly I can't find iframe-id, most likely I misunderstand what I need to do, I'm sorry [Screenshot](https://i.paste.pics/b81590dfe5466358c09acb1f544b2daf.png), [also](https://i.paste.pics/315208a51a4020f5d06aecafa5f0f72b.png) – YuuToso Aug 12 '17 at 04:32
  • This migth no longer work [due to cross-origin restrictions](https://stackoverflow.com/questions/64857289/). – surfmuggle Nov 28 '21 at 19:11