0

I want to access the yellow highlighted span tag value give in the image below:

enter image description here

I tried the following in chrome console but it gives undefined value as follows:

enter image description here

Where am I getting wrong? How do I solve this? How do I get the span value?

z22
  • 10,013
  • 17
  • 70
  • 126
  • 1
    the id is **id_frame** and not **frameID** ???? – cнŝdk Mar 09 '15 at 10:37
  • actually `id_frame` is a temporary id added by me, originally iframe does not have any id, I tried with `id_frame` too in console but it still doesn't work. – z22 Mar 09 '15 at 10:40

2 Answers2

3

You need to use:

$('#id_frame').contents().find('#queuedBetTotal').text();

You should also know that if the iframe source is pointing to a different domain, due to security reasons, you will not be able to access the contents of this iframe in javascript.

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
  • please check my edited question, actually the iFrame does not have any id. – z22 Mar 09 '15 at 10:42
  • @z22: is it from cross domain?? – Milind Anantwar Mar 09 '15 at 10:42
  • yes it's pointing to a different domain, and as you said it is giving security error: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame. How do I access this? – z22 Mar 09 '15 at 10:43
  • You don't need an ID to do that, if it is the only iframe or the first one, you can do $('iframe') – bviale Mar 09 '15 at 10:43
  • @z22: i am not sure whether this would work but you can give it a try http://stackoverflow.com/a/28273086/1719752 – Milind Anantwar Mar 09 '15 at 10:47
  • @MilindAnantwar- thanks for the link, I found that a subset of my current domain`("https://www.somesite.com/ticketpage.html")` checks for the parent origin`(""https://www.somesite.com"")` and hence it throws the error. Trying to solve this now, let me know if you have any idea for this issue. Thanks again – z22 Mar 09 '15 at 11:04
  • have you tried setting the document domain to the domain of iframe server?? `document.domain = 'somesite.com'` – Milind Anantwar Mar 09 '15 at 11:06
  • I found this: http://stackoverflow.com/questions/26329519/uncaught-securityerror-failed-to-read-the-contentdocument-property-from-html. As it says I can't access the elements of iframe with another domain. How do I solve this now? As I don't have access to the website script. Any clue? – z22 Mar 09 '15 at 11:06
1

$('iframe').contents().find('#queuedBetTotal').html(); if you don't have id means you can use the tag name.

Balachandiran
  • 661
  • 1
  • 8
  • 15