473,414 Members | 1,675 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,414 software developers and data experts.

help using external javascript in div

17
Hello, I'm using the Yahoo UI to create a Panel in a custom application. I use ajax to request html from a php page to create the panel. The php page echo's out the entire html page including the src for javascript (which is an external file) for the html page. The returned html is then made into a div with a z-index of 6 to make the panel. This panel has buttons that use functions from the javascript that was passed back from the php page. The buttons/javascript work fine in Firefox, but not at all in IE.

Any thoughts?
Aug 1 '07 #1
11 1907
acoder
16,027 Expert Mod 8TB
Could you show some code or a test page.
Aug 1 '07 #2
naurus
21
could it be that you're using document.getElementById() in your scripts? If you are, IE 6 doesn't support all the web standards, getElementById being one of them.

If that's the case, using this function could help:
Expand|Select|Wrap|Line Numbers
  1. function fetchById(id){
  2.     if (document.getElementById){
  3.         var fetch = document.getElementById(id);
  4.     }
  5.     else if (document.layers){
  6.         var fetch = document.layers[id];
  7.     }
  8.     else if (document.all){
  9.         var fetch = document.all[id];
  10.     }
  11.     return fetch;
  12. }
Just do a search in your document for "document.getElementById(" and use the replace field to replace it with "fetchById(".

Hope that helps,
Naurus
Aug 1 '07 #3
ktrw25
17
A button on the main page calls Panel() which gets the html from PANEL.php This is then displayed in a div on the main page. all the html shows up fine, but the javasript does not work in ie. Works fine in FF.

//**********function that gets the html that we need ****
Expand|Select|Wrap|Line Numbers
  1. function Panel  () {
  2.  
  3.       var returnajax = function(o){
  4.       //returned response is html
  5.       var html = o.responseText;
  6.       YAHOO.namespace("example.container");
  7.  
  8.               YAHOO.callhome.container.panel = new YAHOO.widget.Panel("panel");
  9.  
  10. YAHOO.example.container.panel.setBody(html);
  11. YAHOO.example.container.panel.render(document.body);
  12.  
  13.                        }
  14.       //handle the return
  15.       var handle_return =
  16.       {
  17.         success:returnajax
  18.       };
  19.  
  20.       var url = "PANEL.php";
  21.  
  22.       //get the html from PANEL.php
  23. var get_callhome = YAHOO.util.Connect.asyncRequest('GET', callhomeurl, handle_return);
  24. }
  25.  
*********************PANEL.php**********
[PHP]// php page used for returning the html
echo <<< EOT;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
<script type="text/javascript" src="application/scripts/testscript.js"></script>
<link rel="stylesheet" href="password.css" type = "text/css">
</head>

<body>

<div id="buttons">
<center>
<button class="inputbutton" type="button"id="button1" onclick="test()">New User</button>
</center>
</div>

</body>
</html>
EOT;

[/PHP]**************application/scripts/testscript.js*******
Expand|Select|Wrap|Line Numbers
  1. //function in testscript.js
  2. function test() {
  3.   alert("hello");
  4. }
  5.  
************************************************** ***************
Aug 1 '07 #4
ktrw25
17
IE acts like it is not loading the external script
Aug 1 '07 #5
drhowarddrfine
7,435 Expert 4TB
Change this:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=windows-1250">
To this:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2.    "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  6.  
This gets IE out of 'quirks mode' and brings your page into the 21st century. And it gave me something to do. None of that has anything to do with fixing the problem.

The <center> tag has been deprecated for years. You should use CSS. Of course, you should use a strict doctype, too, but you can't if you use <center>.
Aug 1 '07 #6
ktrw25
17
Replacing that code didn't seem to help matters. Can IE not use an external script from a dynamically created div or am I on the wrong track?
Aug 1 '07 #7
acoder
16,027 Expert Mod 8TB
Replacing that code didn't seem to help matters. Can IE not use an external script from a dynamically created div or am I on the wrong track?
Does the stylesheet work?
Aug 2 '07 #8
ktrw25
17
No the stylesheet does not work either.
Aug 2 '07 #9
acoder
16,027 Expert Mod 8TB
No the stylesheet does not work either.
Then you need to dynamically add the script and the stylesheet to the page using code similar to the following:
Expand|Select|Wrap|Line Numbers
  1. var scrpt = document.createElement("script");
  2. scrpt.src = theurl;
  3. scrpt.type="text/javascript";
  4. document.getElementsByTagName("head")[0].appendChild(scrpt); 
and something similar for the CSS stylesheet. Note that this will only work in modern browsers.
Aug 2 '07 #10
ktrw25
17
Awesome, works great. That's exactly what I wanted it to do.
Aug 2 '07 #11
acoder
16,027 Expert Mod 8TB
Awesome, works great. That's exactly what I wanted it to do.
Glad you got it working. Post back anytime you have any more problems.
Aug 2 '07 #12

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

Similar topics

14
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
2
by: KS | last post by:
I have a folder where i got all my external javascript.js files saved. Using the external.js files in my .jsp files works fin by: <script language="JavaScript"...
8
by: Johnny Knoxville | last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works fine if you add the site to favourites the normal way, but I have some JavaScript code on a couple of pages with a link,...
4
by: Jake j | last post by:
To those of you who sent me working examples of js include routines, much thanks. I see from them examples that what I'm trying to get to requires a higher level of js knowledge than I've got. ...
1
by: KiwiBrian | last post by:
I am using Statcounter to log site visits Upon enquiring whether the service logged visits from my site to external sites using site links I was given the following information:- "You have to...
2
by: Mahesh Devjibhai Dhola | last post by:
Hi, I want to develop p2p (peer-to-peer) communication connection for chat in ..Net (Lang: c# - preferable) NOTE: if two LAN are behind their own router then also it should work as yahoo, msn...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
5
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
2
by: rickky112 | last post by:
Hi all I'm new to this forum and also new to javascript. I have developed a website using asp pages and i'm using a software package incorporated into the asp pages. The external software...
9
by: mevryck | last post by:
Greetings I have a huge Javascript with inclusion of external scripts and all. I got this by doing a XSLT . Now I have the contents in a Javascript variable, but I'm not able to update the...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.