473,469 Members | 1,519 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Iframe load problem

3 New Member
I am trying to load page into iframe in IE7 and change the page bgColor after
the page has loaded.

I tried 2 options:
1. Change the iframe.src from the parent to the new URL.
2. Write div element into the iframe using document.write()
Retrieve the URL using xmlhttp object.
set the div.innerHTML to the xmlHttp.responseText;


The problems:
In option 1 , when trying to access the loaded page in the iframe I get
javascript error access denied.
In option 2 , I can access the page and change the bgColor
but the page is loaded differently in a different look and feel
it seems that the css is not effecting.

Any comments / ideas / other approaches will be welcome.

10'x Eyal
Feb 22 '07 #1
4 3738
acoder
16,027 Recognized Expert Moderator MVP
Is the page from your server?

Post your code so someone can pinpoint the problem.
Feb 22 '07 #2
eyalrab
3 New Member
Is the page from your server?

Post your code so someone can pinpoint the problem.
No the page is loaded from the web.
Feb 22 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
That is probably why you're getting the access denied error.

As for the css, it is a relative reference, so you will have to make it absolute.
Feb 22 '07 #4
eyalrab
3 New Member
That is probably why you're getting the access denied error.

As for the css, it is a relative reference, so you will have to make it absolute.
Please see the code:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <body> 
  3.     <script>
  4.      var xmlHttp= false; 
  5.      function writeResponseHtml() {
  6.            // if xmlhttp shows "loaded"
  7.           if (xmlHttp.readyState == 4) {
  8.  
  9.                if (xmlHttp.status==200) {
  10.                    // ...some code here...
  11.                       response = xmlHttp.responseText;
  12.  
  13.                    //write the HTML to the iframe  
  14.                        try {
  15.                             frames['contentiFrame'].document.write("<html><head></head><body><div id='iDiv'></div></body></html>")  ;                   
  16.                             frames['contentiFrame'].iDiv.innerHTML = response ;
  17.                         } catch (e2) {
  18.                             ;
  19.                         }                
  20.                } else {
  21.                       alert("Problem retrieving XML data")
  22.                       }
  23.           }
  24.      }
  25.  
  26.  
  27.  
  28.      function option1(url) {
  29.  
  30.       // Option one - use the iframe capability of loading url
  31.       // always works but with no ability to touch the loaded page
  32.  
  33.          frames['contentiFrame'].location.href=url; 
  34.          return true;
  35.       }
  36.  
  37.  
  38.  
  39.       function option2(url){
  40.  
  41.       // Option two - use the the xmlhttp to get the html and write it to the iframe using document.write
  42.       // does not work all the time.
  43.  
  44.           try {
  45.                  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  46.              } catch (e) {
  47.                         try {
  48.                                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  49.                         } catch (e2) {
  50.                                xmlHttp = false;
  51.                         }
  52.                }
  53.              if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  54.                    xmlHttp = new XMLHttpRequest();
  55.              }
  56.  
  57.           xmlHttp.open("GET", url, true);
  58.           xmlHttp.onreadystatechange = writeResponseHtml;
  59.           xmlHttp.send(null);          
  60.       }         
  61.     </script>
  62.  
  63.  
  64.     <div id="contentDivID">
  65.  
  66.        <a href="#" onclick="option1('http://www.ask.com');">option1</a>
  67.        <a href="#" onclick="option2('http://www.ask.com');">option2</a>
  68.        <a href="#" onclick="frames['contentiFrame'].document.body.bgColor = 'red';">bgColor</a>          
  69.  
  70.        <iframe id="contentiFrame" width='100%' height='100%' scrolling='auto' ></iframe>
  71.      </div>     
  72.   </body>
  73. </html>
  74.  
  75.  

Do you have any idea how can I do it ?
Feb 22 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tobias Åkeblom | last post by:
I have a mainpage where i display my menu and an iframe for the content to load in. I want to trace keydown events i the Iframe. This works well the first time I load the site. But when I load new...
2
by: Rich | last post by:
Is there any way I can check to see if a document is loaded into the iframe before I call onLoad (sort of an afterLoad). I'm loading up a page into an iframe. But because we use four servers...
5
by: SigRob | last post by:
I have PAGE1 with the link to PAGE2 with iframe. (iframe load several naked html). I want to add directive to the link to point sprcific content of iframe. to make it clear link on PAGE1 ->...
3
by: Stevie_mac | last post by:
It might be me but... I dont seem to get a Page_Load event when a opening an ASPX in an iFrame. I do geta Page_Load event when an item on the ASPX (inside the iFrame) is clicked but then...
2
by: Helen | last post by:
Guys and gals, I am having a problem with an IFRAME that is embedded into an ASPX page (ASP.NET application). The IFRAME is originally empty (src=''). When a user selects a date from the...
12
by: wangzx | last post by:
I am the author of easyajax.sourceforge.net, and I have a problem on Firefox 1.5, I post the problem here and hopes somebody help me. The test page can be:...
3
polymorphic
by: polymorphic | last post by:
I have succeeded in embedding PDF files in a dynamic iframe. The problem is that I need the PDF to cache. If the PDF remains the same from page load to page load then the pdf is somehow cached with...
1
by: epower | last post by:
Hello, I am working on an ASP .NET application in Visual Studio 2005 and running IE7. This application has a page that contains an iframe which loads an .aspx page and hyperlinks that...
4
by: sukhmeet | last post by:
Hi, I am trying to load a csv file in Iframe element. I just want to load it as a text file. however when i load the file in iframe it asks to open the file and finally opens it with excel in IE...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.