473,396 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to Load a page with javascript into a div problem

I am currently working on a website project. The sites are loaded into a <div> by using ajax. Everything was working well until I tried to load a page into a <div> with some sort of javascript code on that page. The javascript didn't run after that site had been loaded into that <div>.
For example This is the <div> tag on the main page:
Expand|Select|Wrap|Line Numbers
  1.  <div id="loadPage"> </div>
I tried to load another page into that div:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <script type="javascript/text"> 
  4. alert('TEST'); document.write('Doesn't work');</script>
  5. </body>
  6. </html>
  7.  
None of those javascript lines were executive.

Pretty easy. I used DOM method to detach the body part.
Expand|Select|Wrap|Line Numbers
  1. function makeAjaxObject()
  2. {    
  3.     //For older broswsers and IE
  4.     var xmlObj = false;
  5.  
  6.     try
  7.     {
  8.         xmlObj = new ActiveXObject("Msxml2.XMLHTTP");
  9.     }
  10.     catch(e)
  11.     {
  12.         try
  13.         {
  14.             xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  15.         }
  16.         catch(e2)
  17.         {
  18.             xmlObj = false;
  19.         }
  20.     }
  21.     //For browers that support XMLHTTP
  22.     if (!xmlObj && typeof XMLHttpRequest != 'undefined')
  23.       {
  24.           xmlObj = new XMLHttpRequest();
  25.       }
  26.  
  27.     return xmlObj;
  28. }        
  29.  
  30.  
And then make an object and
Expand|Select|Wrap|Line Numbers
  1. document.getElementById(pageLoaderDivID).innerHTML = getBody(loadedContent);            
  2.  
May 28 '10 #1
7 2070
RamananKalirajan
608 512MB
Can you please post the code how you are loading that page

Thanks and Regards
Ramanan Kalirajan
May 28 '10 #2
Any help please? Has anyone tried to load a page with javascript on it to a <div> and that javascript code still worked?
May 28 '10 #3
Dormilich
8,658 Expert Mod 8TB
javascript code that is loaded through AJAX is not parsed by the JavaScript engine. you have to eval() it or something like that to make use of it.
May 28 '10 #4
Thank you Dormilich. I will find out the other way then
May 29 '10 #5
RamananKalirajan
608 512MB
Can I know why you are using document.write. Because whatever the value you are having in the body you are going to place inside a div. document.write is going to write the value on load of the page. Instead of that you can directly give the value. its my suggestion.

Thanks and Regards
Ramanan Kalirajan
May 30 '10 #6
@RamananKalirajan
That was just an example that I wrote. I didn't copy my code because I couldn't access it at that time. :)
May 31 '10 #7
acoder
16,027 Expert Mod 8TB
Besides using eval, the other options are to already have the code included on the page (I realise that may not always be possible or feasible or efficient), or include the JavaScript source dynamically to the head:
Expand|Select|Wrap|Line Numbers
  1. var script = document.createElement("script");
  2. // set src and type
  3. script.src = ...
  4. head.appendChild(script);
Jun 2 '10 #8

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

Similar topics

2
by: Anshul Seth | last post by:
I have been dealing with the page-break problem for long, and have not been able to come to a solution. I am using XSL:FO to generate PDF report for my XML, generating it in tables. I want that...
3
by: Francois | last post by:
Is it possible to automatically create an array on load page? I want my script to be external. (<script language="JavaScript" src="somescript.js"></script>) Several pages should use this...
3
by: Andy | last post by:
Hi, I am complete JavaScript novice and would really appreciate some help with this code: ===================================================================== <%@LANGUAGE="VBSCRIPT"...
6
by: David | last post by:
Hi, I have text link on each record displayed. This needs to open a new small window for entering some data, I cannot seem to fix it ? Hyperlink Code as is: ..... RS("Manual") &...
3
by: Shapper | last post by:
Hello, I am working on an ASP.NET/VB web site. I have several links including menu links. Considerer a want to load a page named page.aspx. I can do it using javascript. Or using this code:...
4
by: Lloyd Dupont | last post by:
I would like to write a link which: - trigger an action & post to an other page the problem I have, while experimenting with asp Button and cross page button the method is not called in case of...
2
by: mwallis76 | last post by:
I am in the stages of pushing up web app to a production server and I am running into an error that I cannot seem trace down. I have a page that allows one to change their password and runs just...
0
by: tony | last post by:
I am working on a PHP project and having a partial page loading problem randomly. The PHP module 4.4.0 is running on apache server 1.3.33, with database connection to oracle 10g. The problem...
2
by: darren | last post by:
I have a small Javascript problem with that mutch love web browser safari, I tested the code on all other browsers PC (Win) and Linux and IE on the mac and it seams to work ok, but for some reason...
2
by: shekharanjali | last post by:
hi, i have a page refresh problem , when the page is refreshed the last query or the command gets executed, is this problem something to do with cookies.please reply. thanks
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.