David,

What I generally do is one of two things:

1. For actions that are only to be executed through _javascript_, I use <a href="" ... >

As Nasir mentioned, "_javascript_:void (0);" will take care of the href attribute and prevent navigation away from the page.

2. For actions for which I want functionality when _javascript_ is not available, I use <a href="" ... >

The "return false;" will prevent the href location from being loaded.  In the case of pop up windows, I generally set the href to a URL that will directly access the content with a target attribute of "_blank" (or if I only want one window opening up, I'll set the target to a name that I use on all anchor tags) for people who don't have _javascript_.  This method works nicely for sites that will be accessed by mobile devices.

Here's an simplified example from a page I set up with a tabbed inferface:
<a href="/path/to/main/page/tab1" onclick="Browser.ActivateTab ('tab1'); return false;">
<a href="/path/to/main/page/tab2" onclick="Browser.ActivateTab ('tab2'); return false;">

With _javascript_ enabled, the onclick calls a function that loads (via a Prototype Ajax call on this page) the just content for the selected tab.  Without _javascript_, the entire page will load complete with the content for the selected tab.

Andy

-------- Original Message --------
Subject: Re: [nyphp-talk] Need some JS / HTML help
From: [EMAIL PROTECTED]
Date: Sat, December 22, 2007 9:32 pm
To: "NYPHP Talk" <[email protected]>


Sorry, didn't mean to send a short and Curt reply. _javascript_:void(0) in the herf will stop the browser from navigating away from the current page. i have used it in similar situations, where an onclick is required.

Regards,
Nasir

Sent via BlackBerry from T-Mobile

-----Original Message-----
From: David Krings <ramons@gmx.net>

Date: Sat, 22 Dec 2007 21:06:15
To:NYPHP Talk <talk@lists.nyphp.org>
Subject: Re: [nyphp-talk] Need some JS / HTML help


Hi!

Thanks Nestor, your examples helped at least to point me to the right
direction although you didn't copy the popup code, but the stuff that is in
the popup window. But I found the source page and could figure it out,
although their approach didn't work for me, but see below.

Néstor wrote:
> Here is an ezample on how to do it with a popup but I think that you can
> also do it
> if you put a link and set the target to blank "target=blank"
>

OK, I got the target in the regular hyperlink all set and that works at least
for those cases where _javascript_ isn't an option. I still can't get anything
from _javascript_. What I did see in the Defintive Guide that one can write the
JS code into the fref attribute. That causes the browser to render the link,
which it didn't do before, and it opens the desired window, but it also
navigates away from the source page and in Firefox at least shows a blank page
with the text [object window]. It is halfways there, but as bad as before somehow.
But while I was writing this I got another idea that led to another idea and
some more googling and now I got it. I don't really know why it works, but it
does work:
<a href=""
http://localhost:8080/file:/F:/piviviewer/include/help/en_us/Default_CSH.htm#100" target="_blank">http://localhost:8080/file:/F:/piviviewer/include/help/en_us/Default_CSH.htm#100',
'HelpWindow',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,width=350,height=250');">?</a>

What I'm surprised about is that in order to get a link rendered the href
attribute needs to be present, but when no URL is specified the click on the
link doesn't do anything, but the onClick event fires and executes the code.

But then I tried a subsequent link / button and as it turns out the popup is
behind the main window. So I needed to find a way to give it focus and after
some more googling I got this:

<button http://localhost:8080/file:/F:/piviviewer/include/help/en_us/Default_CSH.htm#100" target="_blank">http://localhost:8080/file:/F:/piviviewer/include/help/en_us/Default_CSH.htm#100',
'HelpWindow',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,width=800,height=550');
w.focus(); return false;">Help Me</button><noscript><a
href=""http://localhost:8080/file:/F:/piviviewer/include/help/en_us/Default_CSH.htm#100" target="_blank">http://localhost:8080/file:/F:/piviviewer/include/help/en_us/Default_CSH.htm#100"
target="HelpWindow">Help Me</a></noscript>

And I got the CSH portion also down and with my little function I can
customize the button caption or only show a ? or have a text link with custom
text. I then tried the code without _javascript_ enabled to see if the
<noscript> portion works, but that doesn't do a thing. If anyone knows how to
add the proper noscript code, let me know.

David


_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to