get document of IFRAME in Safari

I understand it is possible to get document object of a IFRAME in IE via document.get contentWindow.getElementById("IFRAMENAME".document,

Is this possible in Safari bowser?

Thanks
g
newbee2MFCAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VincentPugliaCommented:
Hi,

you should be able to get the document object simply by referring to it:

<iframe name='theFrame' src='xx.html'></iframe>


alert(theFrame.document)
var docObj = theFrame.document
alert(docObj)

if you want to access any of its contents, you simply continue using the DOM:

docObj.body
docObj.scripts
etc.

The only thing you have to be careful of is with 'document.write'
if you want to write to the frame, use
theFrame.document.write(.....)
not
docObj.write(...)

0
ZontarCommented:
<iframe id="myIFrame" src="sourcefile.html"></iframe>

(Add a name attribute for targeting if you need it.)

Try this:

document.getElementById("myIFrame").contentDocument

for the IFRAME's document object and

document.getElementById("myIFrame").contentDocument.defaultView

for its window object.

(These work in Mozilla and appear to be W3C-compliant.)
0
newbee2MFCAuthor Commented:
var iFrame = theDoc.getElementById(id) ;
alert(  iFrame );  //----> display as IFRAME in runtime

alert(iFrame.document); //-> display as undefined
alert(iFrame.contentDocument); //-> display as undefined as well

the code works perfect fine in Mozilla, IE and Netscape
Any idea?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

VincentPugliaCommented:
mind posting some html to support what you said?
0
ZontarCommented:
www.hiveminds.net/jon/test/C_parent_iframe.html -- uses an IFRAME to include an HTML page
www.hiveminds.net/jon/test/C_parent_object.html -- uses an OBJECT to include an HTML page

Both examples work in Mozilla and Opera (but not in MSIE).

0
VincentPugliaCommented:
I'm not sure if this is what you are looking for, but it works for me (ie6.0)
 
 function moveObjectToAnchor()
  {
   var objectAnchor = myObject.document.getElementsByTagName('a');

   for (var i = 0; i < objectAnchor.length; i++)
     if (objectAnchor[i].name == 'myAnchor')
         objectAnchor = objectAnchor[i]
   myObject.scrollTo(0, objectAnchor.offsetTop);
  }
</script></head>

<body id="parentBody">
.....blahblaha
<p><a href="javascript:moveObjectToAnchor();">Make the OBJECT scroll</a>.</p>
<p>(reload page to try again)</p>
<p>blah blah blah</p>
<iframe id="myObject" width="250" height="250" type="text/html" name='myObject' src="C_parent_object_files/C_iframe.html"></iframe>
.....

Vinny
0
ZontarCommented:
Using something like myIFrame in place of document.getElementById("myIFrame") is nonstandard and works on MSIE only. It's not a good habit to be in if you want scripts to work cross-browser. document.scripts is also IE-only. If you stick with W3C DOM your scripts will work in all of the version 5+ browsers about 80-90% of the time.

>  the code works perfect fine in Mozilla, IE and Netscape

Which code did you mean?



0
ZontarCommented:
> alert(iFrame.document); //-> display as undefined
> alert(iFrame.contentDocument); //-> display as undefined as well

This was in Safari? Please be specific. Thanks.
0
VincentPugliaCommented:
Hi Zontar

  Which is non-standard -- Netscape 6.1 or Mozilla Firebird or IE6 ?  They all were tested with the code posted above.  

  So, I guess your above statement is not only ill-advised, but wrong.


Vinny
0
ZontarCommented:
Hold on a minute, I think we've got a disconnect happening here. Let's review:

<iframe id="myIFrame" src="myfile.html"></iframe>

alert(MyIFrame);

Result:
Mozilla 1.5 -- Error: MyIFrame is not defined.
MSIE 6.0 -- displays: [object]
Opera 7.2 -- displays: [objectObject]

So yes this will get a reference to the iframe in MSIE and Opera, but -- as I've been saying -- it doesn't work in Mozilla, and it's not per the DOM specs.

<iframe name="myIFrame" src="myfile.html"></iframe>

alert(MyIFrame);

Result:
Mozilla 1.5 -- displays: [object Window]
MSIE 6.0 -- displays: [object]
Opera 7.2 -- displays: [objectObject]

Yes, this gets a reference to the iframe in all three browsers. I never said it didn't.

But it's still a nonstandard shortcut for document.frames["myIFrame"]. It causes an overabundance of and over-reliance on global variables. It's not in the W3C DOM spec. It's not supported in XML. It is definitely not supported in serverside DOM. It will definitely not be supported when XML/XHTML-compliant browsers are the norm -- which may happen sooner than you think.

Another issue is that the name attribute will be phased out in future versions of HTML/XHTML. So will frames (including iframes).

Make fun of me if you want, but I'm just trying to stay ahead of the curve.
0
VincentPugliaCommented:
Staying ahead of the curve is well and fine -- as long as you remember you are still part of the curve and that the rest of the world is concerned about realities.

1) Again, I tested with Mozilla Firebird, NN6.1, IE6.0 -- I make no sweeping claims on things I have not tested with.
2)
3) At this present moment in time, the code I posted above is standard, irregardless of what you may believe
4) There are X million users on the internet; of those, Y% use M$-compatible browsers, Z% are connected through providers such as AOL, MSN, EarthLink -- now I wonder...how many of those millions of people do you believe will ever get a chance to use XML/ serverside DOM/ XHTML / etc. /etc. ?  My guess: 1% and I am being generous.
5) there is a difference between 'standards and recommendations' and the real world.  The code in the page you posted will not execute for IE.  I guess you are proposing that people should upgrade their IEs for a non-existent standards-compliant browser?
   "Non-existent" because it is the nature of the beast to be a moving target.  By the time a browser reaches compliance, standards will change -- and don't tell me there is a browser out there right now that is compliant because there is none; they all fall short to some degree.

  So, I guess you are telling newbee that the code I posted shouldn't be used because -- while it works in probably every browser -- it won't be supported ten/twenty years down the road.

  I don't have to make fun of you; you are doing a good enough job of it yourself

Vinny
0
newbee2MFCAuthor Commented:
ok, guys... I figured out this myself....

my IFRAME definition was using "src=../myfolder/blank.gif".  It worked well after I changed to "src=../myfolder/blank.html".

The code worked fine in IE, Netscape and Mozilla...  but Safari.

I am wondering it this is a Safari bug or non-standard issue?
0
VincentPugliaCommented:
Hi newbee,

 Not having Safari, I can't say definitively.  Check with the Safari support forum (they should have one, or at least a link to one on their main site.)

Vinny
0
jaysolomonCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0
Computer101Commented:
PAQed, with points refunded (20)

Computer101
E-E Admin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.