2

I can't seem to get an iframe to display a specific element. What am I doing wrong? From a StackOverflow example I'm using the following method:

Note: the iframe is embedded in a phpbb forum and references a page from within the same forum.

<div class="tab-content">
<form id="ucp" method="post" action="">
<div class="tab-pane">
<fieldset class="framed-ucp">
<legend>Manage notifications</legend>
<p>Here you may view all past notifications.</p>    
<div class="row">
<div class="col-md-4">
<ul class="pagination pagination-sm pull-left">
<li><a href="./ucp.php?i=ucp_notifications&amp;mode=notification_list&amp;mark=all&amp;token=cecbf308" class="mark" data-original-title="" title="">Mark all notifications read</a></li></ul>
</div>
</div>
</fieldset>
</div>
</form>
</div>

<iframe id="notify" src="example.com" seamless="seamless" width="1100" height="600">
</iframe>

document.getElementById('notify').contentWindow.document.getElementById('tab-pane')
ggorlen
  • 44,755
  • 7
  • 76
  • 106
aeneas1
  • 33
  • 5
  • Is the `protocol://domain:port` in the iframe the same as the parent page? – Taplar Aug 22 '18 at 22:55
  • doh, thanks for bringing this up, i edited my original post to reflect the answer to your question - the iframe is pulling a page from within the same phobb forum, i.e. it's not pulling from an external website. – aeneas1 Aug 22 '18 at 23:12
  • `tab-pane` is a class not an ID. Also make sure iframe has loaded before looking for elements inside it – charlietfl Aug 22 '18 at 23:23
  • if i change the script to: "document.getElementById('notify').contentWindow.document.getElementByClassName('tab-content')" it still doesn't work.... how would i ensure the iframe loads first? i tried these examples and no love: https://stackoverflow.com/questions/17436881/making-script-wait-until-iframe-has-loaded-before-running – aeneas1 Aug 22 '18 at 23:44
  • this doesn't seem to work either: – aeneas1 Aug 22 '18 at 23:50
  • @aeneas1 Your iframe is going to "example.com" which will be "http://example.com:80" or "http://www.example.com:80". If your page does not match that, such as if the page is on https, then that is going to *not* be considered the same domain and you will not be able to access the iframe contents with javascript. It must be the same protocol domain and port. – Taplar Aug 23 '18 at 14:18

0 Answers0