Javascript: Call top-level window function from inside object

duhaime

I have the following webpage:

<!DOCTYPE html>
<html>
  <head>
    <meta charset='UTF-8'>
  </head>
  <body>
    <script>window.bark = function() {
      console.log('woof')
    }
    </script>
    <object role='img'
      data='https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/android.svg'
      onclick='window.bark()' />
  </body>
</html>

I know that the content inside the object tag has its own document context, but am wondering: is there any way to permit the object to call the function bound to the window?

Grant Gryczan

This would be impossible under your current implementation, and not because the object's window is under a different global context. (In fact, that click event isn't even inside the object's document. It's inside the top document, so scope wouldn't be a problem.)

It's because you can't effectively listen to clicks directly on an object element. The same would apply to an iframe, for example. Click events are triggered inside the element's document, not on the element itself.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to add a button inside a new window object and call the function in JavaScript?

From Dev

Call top level function from groovy method

From Dev

javascript: call function inside object, from a callback function

From Dev

Call object function inside object in javascript

From Dev

Call Get and Set Function inside Object Javascript

From Dev

JavaScript: Dynamically call a function inside an object

From Dev

JavaScript: Dynamically call a function inside an object

From Dev

How to call a function from inside an object

From Dev

How to Call Parent Window JavaScript Function inside iframe

From Dev

how to call user-defined function of a window object in javascript

From Dev

JavaScript call parent function from child object

From Dev

Javascript OR statement on call function from object

From Dev

Dynamically call javascript object function from html

From Dev

JavaScript call parent function from child object

From Dev

Launch top level screen from inside screen

From Dev

javascript object - how to call class variable inside class function

From Dev

javascript object - how to call class variable inside class function

From Dev

Javascript call prototype function from function inside constructor

From Dev

javascript object oriented call function inside function or call function insede var

From Dev

Add top level JSON to Javascript object

From Dev

How to call window.atob() javascript function from java code?

From Dev

Call a function from inside a function?

From Dev

How to call a function from the bottom of a function that placed on top inside controller using AngularJS

From Dev

Javascript: Remove object from array on function call to object

From Dev

OOP JavaScript: Call method from inside of Callback Function

From Dev

How to call external javascript from URL inside function

From Dev

How to call a function inside a scriptcontrol from outside using javascript

From Dev

How To Call A Javascript Function From Inside Jquery When An ID is Clicked

From Dev

Top level window in WinForms

Related Related

  1. 1

    How to add a button inside a new window object and call the function in JavaScript?

  2. 2

    Call top level function from groovy method

  3. 3

    javascript: call function inside object, from a callback function

  4. 4

    Call object function inside object in javascript

  5. 5

    Call Get and Set Function inside Object Javascript

  6. 6

    JavaScript: Dynamically call a function inside an object

  7. 7

    JavaScript: Dynamically call a function inside an object

  8. 8

    How to call a function from inside an object

  9. 9

    How to Call Parent Window JavaScript Function inside iframe

  10. 10

    how to call user-defined function of a window object in javascript

  11. 11

    JavaScript call parent function from child object

  12. 12

    Javascript OR statement on call function from object

  13. 13

    Dynamically call javascript object function from html

  14. 14

    JavaScript call parent function from child object

  15. 15

    Launch top level screen from inside screen

  16. 16

    javascript object - how to call class variable inside class function

  17. 17

    javascript object - how to call class variable inside class function

  18. 18

    Javascript call prototype function from function inside constructor

  19. 19

    javascript object oriented call function inside function or call function insede var

  20. 20

    Add top level JSON to Javascript object

  21. 21

    How to call window.atob() javascript function from java code?

  22. 22

    Call a function from inside a function?

  23. 23

    How to call a function from the bottom of a function that placed on top inside controller using AngularJS

  24. 24

    Javascript: Remove object from array on function call to object

  25. 25

    OOP JavaScript: Call method from inside of Callback Function

  26. 26

    How to call external javascript from URL inside function

  27. 27

    How to call a function inside a scriptcontrol from outside using javascript

  28. 28

    How To Call A Javascript Function From Inside Jquery When An ID is Clicked

  29. 29

    Top level window in WinForms

HotTag

Archive