<a href="javascript"> ??

G

Gernot Frisch

Which is why is it's good practise to create proper links, that will
make
the page work without javascript (possibly a server-side script and
for
instance GET variables). It's twice the coding, but a great
accessible page.
My practise normally is;
1. Make the page work without any javascript.
2. Add javascript where usefull to prevent unneccessary
page-loading.

Unfortunately, not all uses of javascript can be handles this way,
but a lot
can, and should.

full ACK. I want the href to point to the exact same locatino, but use
JS for opening it in a popup window (it's a bible-verse reference
automatism for a forum, like: [bible=gen:1,1], that will create a
small image and a clickable link)

Thank you very much!
 
G

Gernot Frisch

Hi,

I'm currently writing:
<span onclick="window.open(...);">Klick Here</span>

but I want to use the <a href> for this, since it is defined in the
css script the way I want my link to open. Now, if I use a href, the
href will be executed as well. What can I du in order to make the href
not execute if javascript is enabled?


--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
 
E

Evertjan.

Gernot Frisch wrote on 26 jun 2006 in comp.lang.javascript:
Hi,

I'm currently writing:
<span onclick="window.open(...);">Klick Here</span>

but I want to use the <a href> for this, since it is defined in the
css script the way I want my link to open. Now, if I use a href, the
href will be executed as well. What can I du in order to make the href
not execute if javascript is enabled?

onclick="window.open(...);return false;"
 
D

Dag Sunde

Gernot said:
Hi,

I'm currently writing:
<span onclick="window.open(...);">Klick Here</span>

but I want to use the <a href> for this, since it is defined in the
css script the way I want my link to open. Now, if I use a href, the
href will be executed as well. What can I du in order to make the href
not execute if javascript is enabled?

I think the commonly accepted way is to use the following:

<a href="NoJSError.html" onclick="window.open(...); return false;">
Klick Here
</a>

After window.open(...) is executed, return false; will make sure thet
the default action to follow the link is not executed.

If there is no JS available, the NoJSError.html will be shown, explaining
that JavaScript needs to be enabled for your site to work properly.

NOTE:
Even if JS is enabled, if "window.open(...);" fails for some reason,
the "return false;" will not be executed, and the href will be followed.
 
R

Randy Webb

Gernot Frisch said the following on 6/20/2006 10:17 AM:
Which is why is it's good practise to create proper links, that will
make
the page work without javascript (possibly a server-side script and
for
instance GET variables). It's twice the coding, but a great
accessible page.
My practise normally is;
1. Make the page work without any javascript.
2. Add javascript where usefull to prevent unneccessary
page-loading.

Unfortunately, not all uses of javascript can be handles this way,
but a lot
can, and should.

full ACK. I want the href to point to the exact same locatino, but use
JS for opening it in a popup window (it's a bible-verse reference
automatism for a forum, like: [bible=gen:1,1], that will create a
small image and a clickable link)

Thank you very much!

<a href="bibleVerse.html" target="_blank"
onclick="window.open(this.href,this.target);return false">
Bible Verse
</a>

There are still problems with it (the failure of window.open calls) but
using this.href and this.target are a beginning to not having to change
code in two places.

A better alternative would be onclick="return myFunction(this)">

Where myFunction would look up the href, the target, try to open a
window, and return true or false based on results.
 
L

Laurent Vilday

Randy Webb a écrit :
<a href="bibleVerse.html" target="_blank"
onclick="window.open(this.href,this.target);return false">
Bible Verse
</a>

There are still problems with it (the failure of window.open calls) but
using this.href and this.target are a beginning to not having to change
code in two places.

What about :

<a href="bibleVerse.html" target="_blank">
onclick="return !window.open(this.href, this.target);">
Bible Verse
</a>
 
R

Randy Webb

Laurent Vilday said the following on 6/28/2006 8:38 AM:
Randy Webb a écrit :

What about :

<a href="bibleVerse.html" target="_blank">
onclick="return !window.open(this.href, this.target);">
Bible Verse
</a>

It's better but still not fool-proof. It will still fail if you have one
of the outdated popup blockers that either redefine window.open or close
the window after it is opened.
 
G

Gernot Frisch

Randy Webb said:
Laurent Vilday said the following on 6/28/2006 8:38 AM:

It's better but still not fool-proof. It will still fail if you have
one of the outdated popup blockers that either redefine window.open
or close the window after it is opened.

Thank you. I need this just for a feature. If the browser does not
support it, after all it's just a feature.
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top