0

I am trying to get a content window of an iframe.

In JQuery I have been doing this:

$('#loginframe')[0].contentWindow

However, I am unable to use JQuery in angular so trying to do this in a native way without much success:

  var iframe = document.getElementById('loginframe');
  var insideDoc = (iframe.contentWindow || iframe.contentDocument);

What is the correct way to do this?

Thanks!

7
  • Does the iframe need to be indexed too i.e. iframe[0]? Hard to tell without seeing the output of iframe or the page. Commented Mar 2, 2017 at 19:05
  • document.getElementById('loginframe').contentWindow should work. Whenever you ask a question, please explain what the problem was and any error messages. See stackoverflow.com/questions/19693984/… Commented Mar 2, 2017 at 19:09
  • 1
    Are you doing this in AngularJS (1.x) or Angular (2+)? You've tagged the question with both versions, which makes it difficult to answer. Commented Mar 2, 2017 at 19:12
  • @MikeMcCaughan Except that in either case, you're going against the flow, hopefully for some very good reason, and it's really not an angular question at all, just vanilla JS. Commented Mar 2, 2017 at 19:13
  • @JuanMendes I'm not making any judgements about the question's contents, just the fact that it has both tags. If the OP would like to remove both because it has nothing to do with Angular or AngularJS, that would resolve the problem as well :). Commented Mar 2, 2017 at 19:16

1 Answer 1

0

angular.element('#loginframe')[0].contentWindow

Angular uses a stripped down version of jQuery, and angular.element is an alias for the jQuery function.

https://docs.angularjs.org/api/ng/function/angular.element

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, I missed that tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.