You are here: Re: href="javascript:func()" vs href="#" onclick="javascript:func()" « HTML « IT news, forums, messages
Re: href="javascript:func()" vs href="#" onclick="javascript:func()"

Posted by Jim Higson on 06/19/06 09:17

Jonathan N. Little wrote:

> Jim Higson wrote:
>> David Dorward wrote:
>>
>>> Jim Higson wrote:
>>>
>>>> <a href="javascript:whatever()" style="display:none"
>>>> id="js-link">blah</a>
>>>> This way, the link will only be shown if the user has javascript
>>>> enabled.
>>> Or stylesheets disabled or unavailable.
>> JaavScip
>> Like I said in the grandparent post, a better way still is to create the
>> link altogether in js using DOM. Something like:
>>
>> <span id="link-placeholder" />
>> <script type="text/javascript">
>> var a_ele = document.createElement ( 'a );
>> a_ele.setAttribute( 'href', 'javascript:whatever()' );
>> a_ele.appendChild( document.createTextNode( 'blah' ));
>>
>> var placeholder_ele = document.getElementById(
>> "screensaver-intro" ); placeholder_ele.parentNode.replaceChild(
>> a_ele, placeholder_ele );
>> </script>
>>
>> Now, I think that covers all bases?
>>
>
> Well to be precise you only use JavaScript in that post to remove the
> element's styling that was hiding it...not to create the link.

Yes, but I said "Or, if the link must be created on the server-side, try
something like:" and then gave the unhiding example.

Meaning, removing the hiding would be an easy way if for some reason the OP
found it much easier to make the link on the server. I can think of a few
reasons why this might be the case. For example, under MediaWiki media
paths contain md5 hashes that are only easily knowable on the server side.

I suppose you could use PHP to write a literal string value of the hash into
the javascript, but I was just trying to keep things simple.

--
Jim

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация