2

I am getting this error:

Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLObjectElement': Blocked a frame with origin "http://localhost:8089" from accessing a cross-origin frame.(…)

when i try to access the height and width using content document:

var doc = document.getElementsByTagName("object")[0].contentDocument; 
var size = doc.documentElement.getBoundingClientRect(); 
this._imageW = size.width; 
this._imageH = size.height;

this works whena a user loads local files from their computer but not remote url.

i tried using jquery:

this._svg.addEventListener('load',function() {
    this._imageW = jQuery(".SVGImage").width();
    this._imageH = jQuery(".SVGImage").height();
     ...
 ...

it doesnt work on the first load of the image but it works for the second load of the images.

i want a way to access content document for URL inputs (images) how can i access the getBoundingClientRect() method of an svg image loaded as URL?

  • Isn't there a security feature that does not allow you to use client side (javascript,jQuery) in non local domains for frames? – Casey ScriptFu Pharr Jan 26 '16 at 01:17
  • is there a way to do it securely? my JQuery lines from above seem to work. i could use those. but the first load produces incorrect height and width as chrome thinks the image has fully loaded when it hasn't. do you suggest any ways to improve the JQuery code? @Casey –  Jan 26 '16 at 01:25
  • are you placing your function in the $(document).ready(function(){ here...}); I knwo it might seem like dumb question, but making sure. – Casey ScriptFu Pharr Jan 26 '16 at 01:27
  • Can you place it in a fiddle, and I will write it up for you. – Casey ScriptFu Pharr Jan 26 '16 at 01:27
  • You can't access the inner document of an external frame. @Sarah as I told you in [your other question](http://stackoverflow.com/questions/34984029/alternative-to-javascript-load-for-an-object-of-type-image-svg-xml), this is not what you should use to solve your issue. This comment was directed to an other user, not to you, and it adresses an other issue than the one your were having. You may try to `getBoundingClientRect()` on your `` directly but it should be the same as jQuery's `.width()`. – Kaiido Jan 26 '16 at 03:27
  • actually i tried this method that you were showing someone else and it worked in my case as well. it is not the same as the width. the method getBoundingClientRect() actually gets the width and height in time when i call the onload as appose to width and height properties which dont get the correct values the first time. I used this method for my local files but now i am trying to find a method for external svg's. @Kaiido –  Jan 26 '16 at 08:10
  • then try to get the ``'s boundingBox, you won't be able to access inner docs of frame from other origins. That's a security measure, you can't do anything about it. – Kaiido Jan 26 '16 at 08:34

0 Answers0