[Javascript] Iframe: load same URL using JS

Troy III Ajnej trojani2000 at hotmail.com
Thu Feb 26 21:46:44 CST 2009


> Mark:

> This doesn't work, and it doesn't work in HTML either. A single

> iframe is created OK but it is empty.

 

When something is not working in a simple plain HTML, it is futile to

persist in trying to make it work through dhtml. 

 

p.s.:

Might be security restriction, but I doubt it. Because IFRAME is a

documentElement if I'm not wrong, and loading the same content

in both will exactly yield an infinity parallel mirror effect,...

 

 

Regards,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                                      Troy III

                         progressive art enterprise

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 
 
> Date: Wed, 25 Feb 2009 16:44:53 +0000
> From: Mark.Rees at astrazeneca.com
> To: javascript at lists.evolt.org
> Subject: [Javascript] Iframe: load same URL using JS
> 
> Hello
> 
> This doesn't work, and it doesn't work in HTML either. A single iframe is created OK but it is empty.
> 
> I suppose there is some security feature in browsers to stop infinite page loads? The thing is I only wish to do it once (as the code below shows). Just curious as to what is stopping it working.
> 
> function addIframe(){
> //reloads the same page in an iframe
> if(!document.getElementById('iframe')){
> var iFrame=document.createElement('iframe');
> iFrame.width=100;
> iFrame.height=100;
> //for some reason you cannot reload the same page in the parent
> 
> iFrame.src=location.href;
> 
> iFrame.setAttribute('id','iframe');
> document.body.appendChild(iFrame);
> }
> }
> 
> function checkIframe(){
> //checks whether there is already an iframe
> if(!window.frameElement){
> alert('i am the parent page');
> addIframe();
> 
> 
> 
> }else{
> //this never runs
> alert('i am the child page');
> 
> }
> }
> 
> window.onload=checkIframe;
> 
> Mark

_________________________________________________________________
Windows Live™ Hotmail®…more than just e-mail. 
http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_022009


More information about the Javascript mailing list