473,779 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript, Firefox and document.links

He there!
I've discovered that the

=============== =============== =============== ====
document.links( 'link_id_here') .href = "something" ;
=============== =============== =============== ====

is not applicable for the Firefox (even for the 1.0.6), and I'm falling
into passing through the array and checking each link id.

Could anybody confirm it's true and/or direct to a more elegant
solution if any?
Thanx,
Andrew

Aug 31 '05 #1
10 5393


an********@gmai l.com wrote:

I've discovered that the document.links( 'link_id_here') .href = "something" ; is not applicable for the Firefox (even for the 1.0.6)


That will give you an error "document.l inks is not a function" indeed.
Why do you think that document.links is a function?
And if you really have an id why don't you simply use
document.getEle mentById('link_ id_here')
?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 31 '05 #2
Martin Honnen schrieb:


an********@gmai l.com wrote:

I've discovered that the


document.links( 'link_id_here') .href = "something" ;


is not applicable for the Firefox (even for the 1.0.6)

That will give you an error "document.l inks is not a function" indeed.
Why do you think that document.links is a function?
And if you really have an id why don't you simply use
document.getEle mentById('link_ id_here')
?


Correct, document.links is an array, you can get a single element by ie
document.links[0] for the first link in document, the links-count is in
document.links. length and the href isn't called hraf but target:
document.links[0].target.

And the functionality you're looking for has been posted by Martin Honnen, then
you can set the href by

document.getEle mentById('link_ id_here').setAt tribute("href", "something" );
Aug 31 '05 #3
Martin Kurz said the following on 8/31/2005 2:48 PM:
Martin Honnen schrieb:

an********@gm ail.com wrote:
I've discovered that the


document.lin ks('link_id_her e').href = "something" ;


is not applicable for the Firefox (even for the 1.0.6)

That will give you an error "document.l inks is not a function" indeed.
Why do you think that document.links is a function?
And if you really have an id why don't you simply use
document.getEle mentById('link_ id_here')
?

Correct, document.links is an array, you can get a single element by ie
document.links[0] for the first link in document, the links-count is in
document.links. length and the href isn't called hraf but target:
document.links[0].target.

And the functionality you're looking for has been posted by Martin Honnen, then
you can set the href by

document.getEle mentById('link_ id_here').setAt tribute("href", "something" );


And wonder why it doesn't work properly in the majority of browsers
since IE has major problems with setAttribute? Set it dierectly:

document.links['linkNameNotID'].href="new HREF for the link";

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Aug 31 '05 #4
>> document.getEle mentById('link_ id_here').setAt tribute("href",
"something" );

And wonder why it doesn't work properly in the majority of browsers
since IE has major problems with setAttribute? Set it dierectly:

document.links['linkNameNotID'].href="new HREF for the link";


Really? Didn't noticed yet (but all Clients I'm scripting for are on Intranet
and so they're all IE6 (if IE at all) and there I didn't got any problems yet)

But document.links['linkNameNotID'] isn't correct, links is (as posted earlier
an arry, not a hash) - some browser may support this but at least IE 6 does not
(document.links ... is null or not an object)

Martin
Aug 31 '05 #5
Martin Kurz schrieb:
document.get ElementById('li nk_id_here').se tAttribute("hre f",
"something") ;

And wonder why it doesn't work properly in the majority of browsers
since IE has major problems with setAttribute? Set it dierectly:

document.link s['linkNameNotID'].href="new HREF for the link";

Really? Didn't noticed yet (but all Clients I'm scripting for are on Intranet
and so they're all IE6 (if IE at all) and there I didn't got any problems yet)

But document.links['linkNameNotID'] isn't correct, links is (as posted earlier
an arry, not a hash) - some browser may support this but at least IE 6 does not
(document.links ... is null or not an object)

Martin


Well, setAttribute on IE seems to be a little bit intolerant about speeling of
the attributes (in special about the case):

object.setAttri bute(sName, vValue [, iFlags])

If the specified attribute is not already present, the setAttribute method
adds the attribute to the object and sets the value.

Be careful when spelling attribute names. If you set iFlags to 1 and the
sName parameter does not have the same uppercase and lowercase letters as the
attribute, a new attribute is created for the object.

If two or more attributes have the same name, differing only in case, and
iFlags is set to 0, this method assigns values only to the first attribute
created with this name. All other attributes of the same name are ignored.

When setting the CLASS attribute using this method, set the sName to be
"className" , which is the corresponding Dynamic HTML (DHTML) property.

See
http://msdn.microsoft.com/workshop/a...tattribute.asp

So setAttribute("h ref", "URL") shouldn't bring up any problems in IE (as every
other attribute too when regarding the spelling and case) and is working in
Firefox like requested.

Martin
Aug 31 '05 #6
ASM
Martin Kurz wrote:

[attributes]
When setting the CLASS attribute using this method, set the sName to be
"className" , which is the corresponding Dynamic HTML (DHTML) property.

See
http://msdn.microsoft.com/workshop/a...tattribute.asp

So setAttribute("h ref", "URL") shouldn't bring up any problems in IE (as every
other attribute too when regarding the spelling and case) and is working in
Firefox like requested.


Well, I have a question :

What is, for IE, 'type' in an input ?
is that an attribute ?
It seems it is but "readonly" -> link given by M$ ->
http://www.w3.org/TR/2000/WD-DOM-Lev...tml#ID-6043025

My IE (5.2 Mac)
aborts, breaks, functions when 'type' is trying to set
(see example below)

In addition :
My IE needs attribute 'className' as specified in link you gave
but ...
this attribute is not understood by FF ... !
example :

<html>
<script type="text/javascript">
var ind = 0;
function newTextField(id ) {
ind++;
var ntf = document.create Element('INPUT' );
ntf.setAttribut e('className',' inpText'); // IE
ntf.setAttribut e('class','inpT ext'); // others
ntf.id = id+ind; // don't know if ID is an attribute ?

ntf.setAttribut e('type','text' ); // IE breaks function here
ntf.type = 'text'; // all as with this way

var val = 'new field id = '+id+ind;
ntf.setAttribut e('value',val);
var place = document.create Element('P');
place.appendChi ld(ntf);
document.body.a ppendChild(plac e);
}
</script>
<style type="text/css">
..inpText { background:yell ow; border:2px solid red; color:blue }
</style>
<button onclick="newTex tField('nouv'); ">New Field</button>
</html>
--
Stephane Moriaux et son [moins] vieux Mac
Aug 31 '05 #7
Martin Kurz wrote:
[...]
But document.links['linkNameNotID'] isn't correct, links is (as posted earlier
an arry, not a hash)


It's not an array, it's an HTML collection. It is a bit like an array -
it has a length property and you can access the items by index or
name/id - but it does not have array methods like sort, join, etc.

<URL:http://www.w3.org/TR/2000/PR-DOM-Level-2-HTML-20000927/html.html#ID-75708506>
--
Rob
Sep 1 '05 #8
Well, I have a question :

What is, for IE, 'type' in an input ?
is that an attribute ?
It seems it is but "readonly" -> link given by M$ ->
http://www.w3.org/TR/2000/WD-DOM-Lev...tml#ID-6043025
Yes, type on input-element seems to be readonly.
My IE (5.2 Mac)
aborts, breaks, functions when 'type' is trying to set
(see example below)
Well, seems to be a not so good errorhandling on that IE-Version. But what do
you expect in setting a readonly-Attribute? :o)
In addition :
My IE needs attribute 'className' as specified in link you gave
but ...
this attribute is not understood by FF ... !


And that seems to be an error in the FF-Implemantation. className isn't just
specified in the link I gave, it's specified in the
/WD-DOM-Level-1-20000929-Link you gave too. Easiest way seems to me to test an
element of which you know it has a class-attrib in the html-source. So you could
check the correct class-Attribute-name:

if (document.getEl ementById(eleme ntid).getAttrib ute("className" )) {
// use setAttribute("c lassName", "")
} else if (document.getEl ementById(eleme ntid).getAttrib ute("class")) {
// use setAttribute("c lass", "")
} else {
// something else
}

Not the easiest way for setting class-attribs - but the correct one.

What's really interesting on the ff-behavior: Setting the Class the following way

document.getEle mentById(elemen tid).className = "green";

works in both browsers, IE and FF, while

document.getEle mentById(elemen tid).class = "green";

works in none, so FF seems to be a little bit inconsequent.

I prefer this method because of it's the "oficial" way and working - so why
should I use another method that's working on some actual browsers but maybe
won't work in the next generation. If using it this way, if it isn't working in
any browser, at least I can say, that it's the browsers fault, not mine, and
trying to get around the bug in these special cases ;o)

greetings,

Martin
Sep 1 '05 #9
ASM
Martin Kurz wrote:

thanks for answer
Well, I have a question :

What is, for IE, 'type' in an input ?
is that an attribute ?
But, all my question is based on a createElement
and setting its (new) attributes on the fly

where (setting attributes to a virtual element) :
- my IE fall down, errores, breaks, if type it's tried to set
whatever I can test
- my IE wants 'className' as attribute for new class
while my FF wants 'class' for same attribute

All was in my comemted example I give here back :

example :

<html>
<script type="text/javascript">
var ind = 0;
function newTextField(id ) {
ind++;
var ntf = document.create Element('INPUT' );
ntf.setAttribut e('className',' inpText'); // IE way
ntf.setAttribut e('class','inpT ext'); // FF way
ntf.id = id+ind; // don't know if ID is an attribute ?

ntf.setAttribut e('type','text' ); // IE breaks function here
ntf.type = 'text'; // all as with this way

var val = 'new field id = '+id+ind;
ntf.setAttribut e('value',val);
var place = document.create Element('P');
place.appendChi ld(ntf);
document.body.a ppendChild(plac e);
}
</script>
<style type="text/css">
..inpText { background:yell ow; border:2px solid red; color:blue }
</style>
<button onclick="newTex tField('nouv'); ">New Field</button>
</html>
It seems it is but "readonly" -> link given by M$ ->
http://www.w3.org/TR/2000/WD-DOM-Lev...tml#ID-6043025

Yes, type on input-element seems to be readonly.

My IE (5.2 Mac)
aborts, breaks, functions when 'type' is trying to set
(see example below)

Well, seems to be a not so good errorhandling on that IE-Version. But what do
you expect in setting a readonly-Attribute? :o)


I try to tell to that new input element (createElement)
it's attribute would be one of types :
- text
- checkbox
- radio
- button
- submit
- reset
If I (and you, and they, we) can't set this type,
how to do to get some more radio-buttons, or check-boxes, or ... ?

[className]
this attribute is not understood by FF ... !


And that seems to be an error in the FF-Implemantation.

....
if (document.getEl ementById(eleme ntid).getAttrib ute("className" )) {
// use setAttribute("c lassName", "")
No, I am still in createElement
I can't get an attribute not yet set ...
document.getEle mentById(elemen tid).className = "green";

works in both browsers, IE and FF,
Yes, this way all work fine
document.getEle mentById(elemen tid).class = "green";

works in none, so FF seems to be a little bit inconsequent.


It seems to :-/

--
Stephane Moriaux et son [moins] vieux Mac
Sep 1 '05 #10

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

Similar topics

12
1948
by: Howard Kaikow | last post by:
Yesterday, I decided to try Firefox. I've encountered a behavior that is either a bug in Firefox or a bug in my Javascript code. I'll try to explain the problem, hoping that this newsgroup can (in)validate my Javascript code. First, I'll describe the purpose of the Javascript code. I often have a need to post a URL to something at my own web site, e.g., http://www.standards.com/Sorting/SortPerformanceComparison-Description.html. It is...
4
1973
by: DanielEKFA | last post by:
Hey hey :) Having a lot of problems with this. I'm helping my brother out with this art school web page. He has a big wish to have random images from the web shown in the background, and asked me to help him out. My idea is this: Use the CNN Top Stories RSS feed to harvest keywords, then use a random keyword from this harvest to search Google, get links from the result, look through random links here and get links to images, then load...
2
1744
by: Radu Ciurlea | last post by:
Hello. I want to make the browser show some suggestions under a text box (like the To: field in webmail interfaces that displays addresses in the addressbook). Basically whenever something changes in the text box (i.e. an onKeyUp even occurs) I check to see what words in the "address book" match the word in the box. After that I fill a <div> with links that onClick update the text box contents. Here's how it's written: in search.html:
9
2125
by: Astra | last post by:
Hi everybody Wonder if you could help me out. I created a simple JavaScript routine to enable a user to click backwards and forwards between small news articles. This routine works fine in IE and Safari, but in the latest FireFox I get no title or article, but do see the prev and next links and the article number. My HTML and JS simple routine is as follows:
8
3675
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
1
1903
by: Rabel | last post by:
Hi I am updating some pages from a website that is a few years old and I didnt work on the site then, but the javascript works in ie but not in firefox. The scripting is function yyLayerScroll(daTarget, delay, ex, ey, dx, dy, sx, sy, daT, daLoop, daFirst ) { var yyX; var yyY; var target = MM_findObj(daTarget); if(!target.oritop){ target.oritop = (document.layers)?target.top:target.style.top; target.orileft =...
12
2615
by: tim | last post by:
I am using foldoutmenu 3 and am having problems with viewing my menus in firefox. On my sub3 menus i have more than one line of text in some places. firefox does not recognise that there is more than one line and the text simply overlaps the sub-menus below it. I thought i had got around this by placing empty 'spacers' like so; oFoldMenu.make('sub3','')//spacer unfortunately, i have just viewed the site in IExplorer and it has added...
6
5833
by: scotty | last post by:
I have a script that loops through an existing table list and prepares each href element node to trigger a function when an image is clicked. The function that will be run passes a property value to the function upon clicking. The property value is one of the attributes defined for each respective href in the property list. In IE and Netscape, the property values pass correctly, but in Firefox, only the last property value in the list...
1
3671
by: dev08820 | last post by:
I have a javascript function that disables the hrefs on a page by assigning "#" to each href. Th eneed to do so is to disable links in a print preview window. The print preview window contains only page content and not navigation, etc. This works fine in IE6 but not in FireFox 2.0.0.2. In Firefox, the link always contains the current context or location. If a "#" is assigned the href becomes http://www.foo.com/context/currentpage.htm# instead...
0
9633
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
9474
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
10137
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...
1
10074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6724
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
5373
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
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
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.