473,836 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Where to put page-specific JavaScript

I have a little menu system which essentially takes HTML like:

<div id='foo'></div>

and retrieves foo.shtml from the server and inserts it inside the
<div>. But sometimes I'd like foo.shtml to look like:

<script language='JavaS cript'>
...do something AJAX-y
</script>
<div></div>

so that the script fills in the page. I've hacked together something
that inserts the foo.shtml into foo's div then does a
fooDiv.getEleme ntsByTagName('s cript') and uses eval() on them and it
works most of the time in some brossers but it seems hackish and
somewhat dangerous and it doesn't work everywhere. Surely there's an
AJAX idiom (or even a DOM built-in) to execute scripts as parts of
pages load. Can someone enlighten me? TIA.

Feb 26 '07
22 2360
On Mar 1, 12:15 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
Christopher Nelson said the following on 3/1/2007 9:30 AM:
I've got:
var e = document.getEle mentById(id);
e.innerHTML = '<br>'+req.resp onseText;
var h = document.getEle mentsByTagName( 'head')[0];
var scripts = e.getElementsBy TagName('script ');
alert(scripts.l ength+' scripts found for '+id);
for (var i = 0; i < scripts.length; ++i) {
var s = scripts[i];
if (s.innerHTML) {
var x = document.create Element('script ');
x.innerHTML = s.innerHTML;

x.text = s.innerHTML;
Thanks. IE7 gets farther now. It complains about expecting an object
on line 500,000-something and then opens the debugger with most of the
first 10 lines or so of index.html highlighted. :-(

Mar 1 '07 #21
Christopher Nelson said the following on 3/1/2007 12:50 PM:
On Mar 1, 12:15 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
>Christopher Nelson said the following on 3/1/2007 9:30 AM:
>>I've got:
var e = document.getEle mentById(id);
e.innerHTML = '<br>'+req.resp onseText;
var h = document.getEle mentsByTagName( 'head')[0];
var scripts = e.getElementsBy TagName('script ');
alert(scripts.l ength+' scripts found for '+id);
for (var i = 0; i < scripts.length; ++i) {
var s = scripts[i];
if (s.innerHTML) {
var x = document.create Element('script ');
x.innerHTML = s.innerHTML;
x.text = s.innerHTML;

Thanks. IE7 gets farther now. It complains about expecting an object
on line 500,000-something and then opens the debugger with most of the
first 10 lines or so of index.html highlighted. :-(
Start making your page smaller and smaller until you either get a
minimum test case to debug or you get rid of the error. Then start
adding it back and you will find the problem. 500,000 lines of code
though? There is a bug in IE with regards to lines of code though. If
code has more than 32767 lines of un-interrupted code IE will barf all
over it. And even then, it is not all IE's, it is only certain updated IE's.

<URL:
http://groups.google.c om/group/microsoft.publi c.scripting.jsc ript/browse_thread/thread/fcb104c0dbd08fb e/652dd7efe51279f 1?lnk=gst&q=327 67&rnum=1#652dd 7efe51279f1>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 1 '07 #22
On Mar 1, 4:47 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
Christopher Nelson said the following on 3/1/2007 12:50 PM:
...
Thanks. IE7 gets farther now. It complains about expecting an object
on line 500,000-something and then opens the debugger with most of the
first 10 lines or so of index.html highlighted. :-(

Start making your page smaller and smaller until you either get a
minimum test case to debug or you get rid of the error. Then start
adding it back and you will find the problem. 500,000 lines of code
though? ...
Actually, the error is reported on line 5 million and something;
clearly a reporting bug. <shrug>

Mar 2 '07 #23

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3265
by: Alex Vorobiev | last post by:
admittedly, this SP is probably a mess given that I am not a TSQL pro. its purpose is to, based on the arguments, do 1) paging or 2) return prev/next ids for a given record. it does the job, but at the cost of several seconds. i was hoping someone could give me pointers on how to optimize it. perhaps, i should break it down into smaller SPs, or create additional indices on the source table, etc. thank you in advance for your help!
1
11723
by: Michael | last post by:
I have a table that has the following fields: tblECHECK ID (autonumber identity column) PTID Batchnum Page DataPoint DPValue
5
4078
by: Rachel Weeden | last post by:
I'm working on an ASP Web application, and am having syntax issues in a WHERE statement I'm trying to write that uses the CInt Function on a field. Basically, I want to select records using criteria of Race, Gender and Crime Code. But the Crime Code field in the table is text, and I cannot change it. I want to use a range of crime codes, so need to convert it to an integer on-the-fly. Here's what I have in my code so far:
36
4119
by: Jack Hughes | last post by:
This argument has come up two or three times lately. We have a web standards document at our company that say "Use valid HTML 4; We don't recommend switching to DIV-based CSS-P for layout just yet though, tables are a lot easier." That's because we have a lot of developers who aren't ready to move to CSS-P and DIVs just yet. But I'm being told our policies were contradictory. If we're going to
4
1582
by: Maellic | last post by:
Hi, I'm having real trouble locating configuration settings on an existing website. Details follow: I've recently taken over a website developed with ASP.NET. Unfortunately the original developer has left the company and has left no documentation whatsoever. I've successfully managed to make a few updates to the website but I've recently hit a snag.
3
2757
by: sean | last post by:
I have a table with fixed row of records SORTED by DATE using ADO pagination method. The user can click a link in one table cell and go to another page to modify the record. Once the updated record is saved the user will be redirect back to the table. This time the record updated will be highlighted so that the user knows where he came from. I basically pass the page number, column and row number via querystring and store the info in a...
4
1301
by: D | last post by:
Hi I'm obviously still learning here but what I've created is a page with a calendar and button. When I click the button I do a number of tasks and would like to output the progress in messages such as Starting TaskA Processing TaskA Completed TaskA
6
2054
by: Liming | last post by:
Hi, In a typical 3 tier model (view layer, busines layer and data access layer) where do you handle your exceptions? do you let it buble up all the way to the .aspx pages or do you handle it in your business layer and/or data access layer? suppose in my data access layer, I provide try and catch, log the exception and re-throw it back to business layer, then in yoru business layer, what do you do? throw it back to the code behind or...
2
1474
by: Mr. T | last post by:
Hi, i have a master page, and then my aspx page that uses that master page. Now in my aspx i want to use a LinkButton to sort data on my page. My question is where do i put the sub the LinkButton is calling to? If i put it outside the <asp:Content tags i get an error that i can't place it there. When i place the sub inside the content-tags i also get an error that i can't place it there.
3
3347
by: saundra | last post by:
This appears to be the code that is giving me trouble. Can someone help <? include("common.php"); require_once("$HeaderFile"); if(empty($_GET)){ $Start = '0'; }else{ $Start = $_GET;
0
9820
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9670
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10844
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10254
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6979
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5649
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4452
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4016
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3115
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.