Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Pages: [1] 2 3

Author Topic: JS a href="#" - hum hum  (Read 4179 times)

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
JS a href="#" - hum hum
« on: December 09, 2010, 11:41:07 AM »

 :-\
If I’ve made some progress on PHP, Javascript is not yet my cup of tea.

I’m trying since an hour now to fix an issue with this code:
Code: [Select]
<script>
function showHide(shID) {
   if (document.getElementById(shID)) {
      if (document.getElementById(shID+'-show').style.display != 'none') {
         document.getElementById(shID+'-show').style.display = 'none';
         document.getElementById(shID).style.display = 'block';
      }
      else {
         document.getElementById(shID+'-show').style.display = 'inline';
         document.getElementById(shID).style.display = 'none';
      }
   }
}
</script>
The code inside sNews is this one:
Code: [Select]
<a href="#" id="example-show" class="showLink" onclick="showHide('example');return false;">See more.</a>
<div id="example" class="more">
<p>Congratulations! You've just disvovered the hidden Div.<br />
Clicking the link below will hide the Div again.</p>
<p><a href="#" id="example-hide" class="hideLink" onclick="showHide('example');return false;">Hide this content.</a></p>
Yes, apart, there’s some CSS but this is another story.

The problemo is the following: if the user click the a href="#" link then he will land on the homepage.
I know I’ve had this issue in another sNews life but I don’t remember how. :-[

Does someone know here how I can use this script?
Thanks in advance.


skian

  • Full Member
  • ***
  • Karma: 14
  • Posts: 120
Re: JS a href="#" - hum hum
« Reply #1 on: December 09, 2010, 02:13:03 PM »

If you copy-paste this exact code in a blank html file - this works; the href is not followed.
Thus we cannot reproduce your pb.

However, please, use jquery for such needs.
Logged

skian

  • Full Member
  • ***
  • Karma: 14
  • Posts: 120
Re: JS a href="#" - hum hum
« Reply #2 on: December 09, 2010, 02:47:31 PM »

To clarify about JQuery.

Your page should looks like that :

Code: [Select]
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/
1.4.4/jquery.min.js"></script>
</head>
<body>

<script>
$(document).ready(function(){
   $('.more').hide(); // Hide even though it's already hidden
   $('a.showLink').click(function() {
      $('#'+this.rel).toggle(400); // First click should toggle to 'show'
      return false;
   });
   $('a.hideLink').click(function() {
      $('#'+this.rel).hide(400);
      return false;
   });
});
</script>
<a href="#" class="showLink" rel="example">See more.</a>
<div id="example" class="more">
<p>Congratulations! You've just disvovered the hidden Div.<br />
Clicking the link below will hide the Div again.</p>
<p><a href="#" class="hideLink" rel="example">Hide this content.</a></p>

</body>
</html>
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: JS a href="#" - hum hum
« Reply #3 on: December 09, 2010, 02:51:57 PM »

Hello skian and thanks for your reply

I have on my other blog this jQuery solution whiche works fine, but, there,
I didn’t want to use any library at all, so,
I was just wondering if there was a mixed PHP JS way to do this. ???

skian

  • Full Member
  • ***
  • Karma: 14
  • Posts: 120
Re: JS a href="#" - hum hum
« Reply #4 on: December 09, 2010, 03:10:55 PM »

jquery is not mandatory -- it's just strongly recommanded.

You should be able to do it without any lib. And the code you submitted does actually work.
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: JS a href="#" - hum hum
« Reply #5 on: December 09, 2010, 03:17:26 PM »

Yeap it works... on a standalone page as you’ve pointed it out.
But not along the pages when the code is in sNews.
The bloody href="#" leads to the home page.
I surely need an additional and tiny code but I didn’t found it out (except in JS with JQuery :-\)

skian

  • Full Member
  • ***
  • Karma: 14
  • Posts: 120
Re: JS a href="#" - hum hum
« Reply #6 on: December 09, 2010, 03:26:22 PM »

the "return false" should avoid that the '#' url is followed.

Test that here : http://mouton-nuage.fr/test.html
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: JS a href="#" - hum hum
« Reply #7 on: December 09, 2010, 03:38:33 PM »

Don’t get what your trying to explain to the forum’s dumber, dear sheep. :-[
I already got the "return false" in the code.

skian

  • Full Member
  • ***
  • Karma: 14
  • Posts: 120
Re: JS a href="#" - hum hum
« Reply #8 on: December 09, 2010, 04:28:01 PM »

I'm trying to explain that I cannot reproduce your # error. And the proof is the link i have provided.
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: JS a href="#" - hum hum
« Reply #9 on: December 09, 2010, 04:40:14 PM »

Stick it in sNews, you’ll see. ;)

skian

  • Full Member
  • ***
  • Karma: 14
  • Posts: 120
Re: JS a href="#" - hum hum
« Reply #10 on: December 09, 2010, 05:29:29 PM »

Stick it in sNews, you’ll see. ;)
Stick it in sNews, you’ll see. ;)
any link ?
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: JS a href="#" - hum hum
« Reply #11 on: December 09, 2010, 05:37:10 PM »

No I can’t, sorry. The website is receiving hundred of visitors due to this page...
why can’t you paste this code in articles function to see  ??? it just take a few seconds...

skian

  • Full Member
  • ***
  • Karma: 14
  • Posts: 120
Re: JS a href="#" - hum hum
« Reply #12 on: December 10, 2010, 06:51:06 PM »

tested with snews - works perfectly
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: JS a href="#" - hum hum
« Reply #13 on: December 11, 2010, 09:26:11 AM »

tested inside the template, yes it works.
Inside the Core with an article, no. :P

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: JS a href="#" - hum hum
« Reply #14 on: March 20, 2011, 03:49:42 PM »

tested inside the template, yes it works. Inside the Core with an article, no. :P

@ Sven.... I came across the same problem using another JQuery function recently. My solution was to remove the #-sign from the href tag (leaving it empty) like so - <a href="" - and it seems to work fine offline. I have not yet tested it online.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU
Pages: [1] 2 3