Using a # in a dummy onclick plus page reload, part 2

L

Logos

I asked about this a while ago, and got a great answer and a reference
to http://www.javascripttoolbox.com/bestpractices/new.php. I just need
to override onclick and return false. No biggie!

However, I discovered that my code worked fine in IE (no # in URL after
click), but not in FF (# appears in URL after click). Can anyone tell
me why?

if(link.attachEvent) { eval("link.attachEvent('onclick',function() {
GB_show('" +part.strDesc +"', '" +INFO_URL_BASE+part.infoUrl +"', 470,
600); return false; },false)"); }

else { eval("link.addEventListener('click',function() { GB_show('"
+part.strDesc +"', '" +INFO_URL_BASE+part.infoUrl +"', 470, 600);
return false; },false)"); }


Thanks for any help you can give!

Tyler
 
L

Logos

In the generated source the link looks like this, btw:

<a href="#" class="rCatalogHeadSortable"
onclick="ts_resortTable(this);return false;">
 
L

Logos

instead of

link =document.createElement("a");
link.setAttribute("href","#");

if(link.attachEvent) { eval("link.attachEvent('onclick',function() {
GB_show('" +part.strDesc +"', '" +INFO_URL_BASE+part.infoUrl +"', 470,
600); return false; },false)");
}
else {
eval("link.addEventListener('click',function() { GB_show('"
+part.strDesc +"', '" +INFO_URL_BASE+part.infoUrl +"', 470, 600);
return false; },false)");
}

I used

try { //IE will not allow name attribute to be set after element
creation
link =document.createElement("<a name='itemNo|" +intPartId +"'
href='#itemNo|" +intPartId +"' />");
} catch (e) {
link =document.createElement("a");
link.setAttribute("name","itemNo|" +intPartId);
link.setAttribute("href","#itemNo|" +intPartId);
}
//when clicking a product description, scroll the anchor clicked to the
top; cannot just use #, as this breaks in FF unless # is defined on the
page
if(link.attachEvent) {
eval("link.attachEvent('onclick',function() { GB_show('" +part.strDesc
+"', '" +INFO_URL_BASE+part.infoUrl +"', 470, 600); },false)");
}
else {
eval("link.addEventListener('click',function() { GB_show('"
+part.strDesc +"', '" +INFO_URL_BASE+part.infoUrl +"', 470, 600);
},false)");
}


which has the added bonus of positioning the item clicked at the top of
the page, very nice for me. I think FF dies because it is looking for
an explicitly defined anchor "#", whereas IE implicitly just scrolls to
the top. Still....I would like to know for sure why my "#" onclick
dies on FF but not IE...
 
R

Robert

Logos said:
In the generated source the link looks like this, btw:

<a href="#" class="rCatalogHeadSortable"
onclick="ts_resortTable(this);return false;">

And does any javascript error occur in Firefox?
Because if it occurs then the "return false" will never be executed.
 
L

Logos

Robert said:
And does any javascript error occur in Firefox?
Because if it occurs then the "return false" will never be executed.

No, the console doesn't show anything. It's very annoying...
 
M

matthew

Just leave the href bit out as far as I can see it doesn't actually do
anything as you are using onclick. In fact is doesn't really have to be
an anchor tag it could be a div. If you are worried about loosing the
pointer cursor add some css for this.
 
L

Logos

Unfortunately many people complain when we leave out the href, as no
info appears in the status bar as to where the link goes. Apparently
quite a bit of our customer base relies on this.

I've also just discovered that this screws up page reload; if the URL
in the address bar contains an #, the page doesn't reload correctly in
FF. Dammit.
 
R

Randy Webb

Logos said the following on 6/19/2006 1:17 PM:
Unfortunately many people complain when we leave out the href, as no
info appears in the status bar as to where the link goes.

Then make the href point to the current page. Have a tooltip that
displays in the page giving information about the link. Seeing "#" in
the statusbar is useless to a user.

But, many people in this group complain when people top post.
Apparently quite a bit of our customer base relies on this.

Yes, many people do use the status bar to know where a link will take them.
I've also just discovered that this screws up page reload; if the URL
in the address bar contains an #, the page doesn't reload correctly in
FF. Dammit.

As for problems with your code, start with the setAttribute problems (IE
has major problems with it) and ditch the eval stuff. Then post a URL to
a sample page that displays the problem.
 
L

Logos

<lol> I am a top poster. I prefer it because it means the newest
material is at the top, so I don't have to actively hunt for the latest
text. I can read previous posts and see the response structure
graphically, so bottom posting is a waste of time in my view. Back
when one just had nn and such for newsgroup reading on one's 'nix
terminal, it made a lot more sense, but unless one is in a text only
environment with 80x24 columns, bottom posting is not useful IMO.
Then make the href point to the current page. Have a tooltip that
displays in the page giving information about the link. Seeing "#" in
the statusbar is useless to a user.

They don't see #, they see the page URL. At least they do on FF and
IE5.5 and above, which is all I am required to code to. In Opera,
those don't even show up as links, though the onclick does work (Opera
rocks for speed!). Anyway, since two of my bosses are the complainers,
and they read email from people who complained about it when I left it
off other pages, in the # goes! It's not my design decision to make,
alas.
As for problems with your code, start with the setAttribute problems (IE
has major problems with it) and ditch the eval stuff. Then post a URL to
a sample page that displays the problem.

I would LOVE to ditch the eval, I hate using it. It offends my sense
of programming style and good programming practices. Unfortunately, I
can't think of any other good way to insert the URL at runtime into the
call; since these pages are dynamically generated, I can't specify
ahead of time. I thought of a couple workarounds, but nothing that
seemed any more efficient or graceful than using eval (eg, chucking
things into a global array hashed on the element's ID and calling
GB_show(_URLs[this.id],470,600)). I'd be happy to hear any suggestions
for alternatives.

I did get rid of the setAttribute stuff already tho:

try { //IE will not allow name attribute to be set after element
creation
link =document.createElement("<a name='itemNo|" +intPartId +"'
href='#itemNo|" +intPartId +"' />");
}
catch (e) {
link =document.createElement("a");
link.setAttribute("name","itemNo|" +intPartId);
link.setAttribute("href","#itemNo|" +intPartId);
}
if(link.attachEvent) {
eval("link.attachEvent('onclick',function() { GB_show('"
+part.strDesc +"', '" +INFO_URL_BASE+part.infoUrl +"', 470, 600);
return false; },false)");
}
else {
eval("link.addEventListener('click',function() { GB_show('"
+part.strDesc +"', '" +INFO_URL_BASE+part.infoUrl +"', 470, 600);
return false; },false)");
}

I don't know why FF puts the # in the location bar when IE does not
when it returns false. I suspect FF evaluates both the href and the
onclick, while IE just evaluates the onclick.

Demo page at
http://65.110.86.247/Product_List3.asp
Relevant code is buried at line 82 in
http://65.110.86.247/ajax/js/view/ViewCatalog.js

Go easy on me, as this is only my second attempt at a web application,
and I'm also playing with a strict MVC architecture. :)

Tyler
 
R

Randy Webb

Logos said the following on 6/19/2006 4:34 PM:
<lol> I am a top poster. I prefer it because it means the newest
material is at the top, so I don't have to actively hunt for the latest
text.

Most of the people here, myself included, are interleaved posters that
ignore top posters.
 
R

Robert

Logos said:
<lol> I am a top poster. I prefer it because it means the newest
material is at the top, so I don't have to actively hunt for the latest
text. I can read previous posts and see the response structure
graphically, so bottom posting is a waste of time in my view.

It may be a "waste of time" for you as the original poster, but for the
people who respond to your and many others threads, and for the casual
readers, it is useful to know what you are replying to, without having
to open other posts in the thread.
Back
when one just had nn and such for newsgroup reading on one's 'nix
terminal, it made a lot more sense, but unless one is in a text only
environment with 80x24 columns, bottom posting is not useful IMO.

I use Thunderbird and it is still useful. And you will think so too when
you search for answers in posts with people that top post.
 
L

Logos

Hm. I guess I am interleaved, and not top then. If you look, my
previous post is interleaved. To be frank, it seems a fairly minor
issue either way, like code indentation prefs. Not to mention
seriously off topic. :)
 
L

Logos

I search for answers in posts frequently, and I find the ones that are
top posted to be far easier to read. I can zip down the thread and
always find the releveant material right at the top. Someone doesn't
*have* to open up the other posts to read what I'm responding to, it's
right there - just bottom to top instead of top to bottom. Really,
it's a matter of preference and style. There is no one true posting
methodology, just like there isn't one true indentation methodology.
The benefits of the types are mutually exclusive; which one appeals
most comes down to personal preference. There's no final answer.
 
R

Randy Webb

Logos said the following on 6/21/2006 4:13 PM:
I search for answers in posts frequently, and I find the ones that are
top posted to be far easier to read.

That is your choice and it is not the preferred method in this group. Do
you not understand or comprehend that? Or, do you choose to ignore it
simply to be annoying?
There is no one true posting methodology, just like there isn't one
true indentation methodology.

There are 4 if you want to be picky about it.

Top-posting.
Bottom-posting.
Not-quoting.
Interleaved.
There's no final answer.

It has been given to you several times already.

Do you drive on the left side of the road simply because it's more
comfortable or do you drive where public consensus agrees to drive? The
principle is the same. The regulars in this group have debated it -
repeatedly in the past - and have come to the consensus that
inter-leaved posting is preferred and that top-posting is despised. It
is even covered - explicitly - in the groups FAQ. The fact that you keep
choosing to ignore that is why you have not had your question answered yet.

If you don't play by the rules, you get ignored and run over.
 
L

Logos

Tony said:
Courtesy is never a minor issue, neither is it ever off-topic.

But if you want to ignore the conventions of this group, by all means,
please do. Odds are the group will end up ignoring you.


It's difficult to comply both with Randy and your notions of courtesy.


Randy states that "But, many people in this group complain when people
top post."

You state that "Most of the people here, myself included, are
interleaved posters that
ignore top posters."

So, without knowing who I'm talking to in advance, and not being able
to format in bottom, top and interleaved formats simultaneously, how
can one observe 'courtesy'? Someone is going to be offended no matter
what. This is why this sort of topic is ridiculous and pointless.
Unless you founded the group yourself, or there is a clear FAQ posted
weekly stating the local bylaws, it's incredibly rude to insist that
everyone else follow your own particular set of rules. Usually when a
FAQ is posted weekly it shows up in pretty much every seach of a
newsgroup, or in the listing of recent posting headers, making it easy
for people to observe protocol.

Searching for FAQ just now, which I usually do before posting to most
newsgroups, there was nothing from this year. In fact, in my search
just now the first hit was
"The FAQ - Making my life easier, and the FAQ better." talking about
how to automate it. From Dec of 2001! (discounting the faq for this
newsgroup posted June 19th; my post was on the 16th, and this seems to
be posted in response). So since the FAQ wasn't being constantly
posted, and nothing obvious showed up searching for just FAQ, I don't
think I was being either rude or discourteous.

(http://www.JavascriptToolbox.com is a fantastic page btw, and I've
been referred to it by people and google before on other occasions - I
never realized it hosted a FAQ for this group, though).

Now that I've had the FAQ pointed out to me, I'm happy to abide by it.
But don't chastise me for not following it when it's not readily
available, and when you contradict it yourself.

Tyler
 
M

Matt Kruse

Logos said:
(http://www.JavascriptToolbox.com is a fantastic page btw, and I've
been referred to it by people and google before on other occasions - I
never realized it hosted a FAQ for this group, though).

It doesn't actually host the group's FAQ - it merely points to it at
jibbering.com.
I wrote a "newbie FAQ" to address some of the most common posting complaints
here, as well as a best practices document. These are both hosted on my
site.
Now that I've had the FAQ pointed out to me, I'm happy to abide by it.
But don't chastise me for not following it when it's not readily
available, and when you contradict it yourself.

The fact that people here insist on adherence to the FAQ, yet the document
itself is very outdated and overwhelming is a contradiction which many
choose to ignore. Stale documentation is sometimes worse than no
documentation at all.
 
L

Logos

Now that I've had the FAQ pointed out to me, I'm happy to abide by it.
But don't chastise me for not following it when it's not readily
available, and when you contradict it yourself.

Hm. I apologize for that, I was kind of annoyed and not thinking
clearly about it. He never says anything about what way things SHOULD
be posted, I just assumed that he meant bottom instead of top posting.
But he never acually says one way of the other. Reading the FAQ (which
is hosted on two separate domains, http://www.javascripttoolbox.com/clj
and http://jibbering.com/faq?) does say that interleaving is the
preferred way. Most of the time that's the way I post/reply to email,
too, is the funny part.

But I'd like to reiterate that the FAQ wasn't readily available/obvious
in the group itself, in my defense.

Anyways, I think I've made enough of a jackass of myself here for now,
and appreciate the help that was given earlier, and would appreciate
any further help if anyone still wants to offer it.

Tyler
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Wed, 21 Jun 2006 16:31:05 remote, seen in
Randy Webb said:
Do you drive on the left side of the road simply because it's more
comfortable or do you drive where public consensus agrees to drive?

In my case, both, really; and it's nice as the driver to be sitting
nearer the middle of the road.

comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly

Your last word needs updating.
 
J

Jeremy

Logos said:
However, I discovered that my code worked fine in IE (no # in URL after
click), but not in FF (# appears in URL after click). Can anyone tell
me why?

Tyler

Try using href="javascript:void;" instead of href="#". This will cause
the link to just do nothing, rather than do something (attempting to
move to the anchor tag with a blank name).

Well, technically it's doing "something", but that something is just
executing an empty javascript statement and ignoring the result.

Jeremy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top