473,594 Members | 2,768 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="javas cript">

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

</script>
</head>
<body>

<table>

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

</td>
</tr>

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

</table>

</body>

Oct 25 '05 #1
4 2019
fc*****@gmail.c om 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_t itle()',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.mozil la.org/en/docs/DOM:document.ti tle>

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="javas cript">


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="javas cript">
document.title= 'Test compatibility IE and FireFox.';
</script>

Oct 25 '05 #3
VK

fc*****@gmail.c om 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="javas cript">
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="javas cript">
// Executed immediately:
document.title= 'Foo';

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

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

Oct 25 '05 #4
fc*****@gmail.c om 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="javas cript">
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.getEle mentById('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
1827
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. However, when I try to access the example via a webserver and Firefox, it doesn't work. Any help with this would be greatly appreciated. (Code listed below:) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2
7419
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: document.getElementById(showDiv) has no properties. Any advice would be much appreciated. Here is the snippet of applicable code; <script language="javascript">
18
2196
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 h(a){document.writeln(a)}
18
43533
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. (It's for Google Maps, but I won't bore you with the complexities of that, as it doesn't affect the question). Mochas kudos to anyone able to solve this widdle.
1
15657
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 addition to the event object. Here is an HTML page that demonstrates the problem. Notice that it works in IE but not firefox.
1
2624
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}" onsubmit="return testTheForm(this)"> javascript function: <script type="text/javascript"> function testTheForm(theForm){
1
1679
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 which submenu is currently displayed and reopen that menu on a new page load. checkCookie() is called onload and switchMenu(menuidhere) when the main menu item is clicked to make the submenu appear. Firefox doesn't display any js errors and...
2
10906
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 script block, I call the python function and store the return value in a variable. I need to be able to display this returned value on the webpage that the xsl generates. I tried to do a document.write() but found that document.write() causes...
3
2627
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
7876
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
8251
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
8372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8234
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
3859
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...
0
3897
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2385
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
1
1478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1210
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.