473,503 Members | 10,322 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript function launch under firefox

Hello,

I've got a little problem with <script></script> under firefox 1.0.7
If the script is not placed in the body tag, it isn't automaticaly
executed, but it is under Internet Explorer.

Here's an example of what i do.

Do anybody have any idea?

I am obliged to put the function in the <body onlaod=""> ?

Where can i find a specification of this kind of thing

<html>
<head>
<title></title>
<script language="javascript">

//////////////////////
function f_title ()
{
document.title='Test compatibility IE and FireFox.';
}

</script>
</head>
<body>

<table>

<tr>
<td>
Bas example : show the title
<a href="javascript:f_title ();">
GO
</a>

</td>
</tr>

<script language="javascript">
document.title='Test compatibility IE and FireFox.';
</script>

</table>

</body>

Oct 25 '05 #1
4 2009
fc*****@gmail.com wrote:
Hello,

I've got a little problem with <script></script> under firefox 1.0.7
If the script is not placed in the body tag, it isn't automaticaly
executed, but it is under Internet Explorer.
What I think you are saying is that if you try to modify the title by
running a script in the head element, and the title element has no
content or contains only whitespace, then Mozilla does not update the
title value.

However, Mozilla will update the value if the script is run after the
head finishes loading (i.e. is called from the body or onload).

So your choice is to:

- run it onload:
window.onload = f_title;

- put some innocuous character in the title element:
<title>-</title>

- run it from the head but use setTimeout to delay its execution
setTimeout('f_title()',0);
I think either of the first two is the best.


Here's an example of what i do.

Do anybody have any idea?

I am obliged to put the function in the <body onlaod=""> ?

Where can i find a specification of this kind of thing

document.title is documented at Mozilla and W3C (and likely Microsoft
too, but you're really asking about Mozilla, right?).

Mozilla.org:
<URL:http://developer.mozilla.org/en/docs/DOM:document.title>

W3C:
<UUURL:http://www.w3.org/TR/2000/WD-DOM-Level-2-HTML-20001113/html.html#ID-18446827>

If you are referring to the vagaries of browser behaviour... welcome to
the wonderful world of browser scripting!

<html>
<head>
<title></title>
If you put some content in the title element, you'll get what I expect
is your expected behaviour.
<script language="javascript">


The language is depreciated, type is required:

<script type="text/javascript">
[...]
--
Rob
Oct 25 '05 #2
OK, thanks for the tips.

THe real thing is, for me, to know why the scripts tags in the body are
executed under IE and not under Firefox. The "title" aspect of my
example is just ... an example.

Why is this script executed ? Is it random on the browser ?

<script language="javascript">
document.title='Test compatibility IE and FireFox.';
</script>

Oct 25 '05 #3
VK

fc*****@gmail.com wrote:
OK, thanks for the tips.

THe real thing is, for me, to know why the scripts tags in the body are
executed under IE and not under Firefox. The "title" aspect of my
example is just ... an example.

Why is this script executed ? Is it random on the browser ?

<script language="javascript">
document.title='Test compatibility IE and FireFox.';
</script>


You're mixing direct statements execution and function declarations.
There is not any major difference here between browsers. Study this
sample (see also suggested format for pseudo-links):

<html>
<head>
<title>Direct statements vs. Functions</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script language="javascript">
// Executed immediately:
document.title='Foo';

// Waits for function call:
function changeTitle() {
document.title = 'Bar';
return false;
}
</script>
</head>

<body bgcolor="#FFFFFF">
<p><a href="noscript.html" onClick="return changeTitle()">Change
title</a></p>
</body>
</html>

Oct 25 '05 #4
fc*****@gmail.com wrote:
OK, thanks for the tips.

THe real thing is, for me, to know why the scripts tags in the body are
executed under IE and not under Firefox. The "title" aspect of my
example is just ... an example.

Why is this script executed ? Is it random on the browser ?

<script language="javascript">
document.title='Test compatibility IE and FireFox.';
</script>


As VK says, in general there is no difference between browsers in this
regard. Scripts in the head (or anywhere else) are parsed and run as
they are encountered. You hit on a quirk of Firefox regarding the
title element - put the script before the title tags in the source and
all browsers will probably barf with an 'object not found' error.

In general, don't call any code that references, access or modifies an
element until that element's source has been parsed and and its object
added to the DOM.

Such scripts are usually placed after the elements they reference in
the HTML source (i.e. after the element's closing tag) or by calling
the functions/running statements using window.onload (or the body
onload attribute, which is essentially the same thing).
The classic case is something like:

<script type="text/javascript">
document.getElementById('blah').innerHTML = 'Found Blah';
</script>

<div id="blah"></div>
Which will almost certainly produce an error in all browsers. Put the
div before the script and all is fine.
--
Rob
Oct 25 '05 #5

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

Similar topics

9
1816
by: Joe | last post by:
I'm trying to create an image preview function so that my users can preview images before they upload them. I've got my example working locally on both Firefox and IE, and from the webserver in IE....
2
7411
by: Cy | last post by:
Hi, I have a menu that toggles correctly in IE but is failing in FireFox V.1 and Netscape 7.1. The FireFox JavaScript Console is returning the following error; Error:...
18
2169
by: marcokrechting | last post by:
Hi All, I have a rather complicated problem. I use following function to display a hyperlink: a="<"+"a href='"; b3="<"+"a href='http://nww."; L="</"+'a><br>'; function...
18
43515
by: Chris Ianson | last post by:
Hi geniuses (or is that genii, or genies) The challenge is as above really. I have a page with an iframe in it, and need to call a JS function in the *parent* page, *from* inside the iframe. ...
1
15646
by: acl123 | last post by:
Hi, I am trying to work out how to access the event object in firefox under two conditions - 1) Attaching event handlers in javascript, not html. 2) The event handler requires parameters in...
1
2609
by: tgorton | last post by:
I am having a problem running a javascript function as part of an html-el:form onsubmit. The problem seems to exists in IE6 but not in Firefox. html: <html-el:form action="${target}"...
1
1671
by: Rewire | last post by:
This script seems to work fine with firefox but not with IE. It just sets style="display:none" or style="display:" to show / hide submenu items on my menu. I've just tried making it save to a cookie...
2
10894
by: neeebs | last post by:
Hi, I'm not sure if this is a javascript problem per se, but here goes. I have an xsl document with a python function defined within a <script> block. Elsewhere in the xsl file, within a python...
3
2620
by: Anz | last post by:
Is there any javascript function available to set the default home page which would work properly in firefox ?, I didn't find any javascript function which will work on firefox, If there any?
0
7207
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
7294
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
7361
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
7015
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
7470
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
5602
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
5026
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
1523
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 ...
0
403
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...

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.