Jump to content

Recommended Posts

Does anyone know how to get anchor from one page to another in WHMCS to works?

On the same page it works fine!

Share this post


Link to post
Share on other sites

The link needs to include the page as well as the anchor, ie: link-to-page.php#anchor

Share this post


Link to post
Share on other sites

Thanks for the answer, but have tried this and it doesn't work.

Also tried "id=" and "name="

Share this post


Link to post
Share on other sites

between which pages are you trying to do it ? if it were two customs, bear's code would work I think, or two pages with no redirection.... but if there's redirection in play... hmm

Share this post


Link to post
Share on other sites

It`s between 2 custom pages, no redirection.
Here is the code I use in the .tpl files:

<a href='site2.php#targetanchor'>Linking from here</a>
...
<a id='targetanchor'>Linking to here</a>

 

Share this post


Link to post
Share on other sites

You don't generally link to an "A" tag, but that should still work, since it's the ID that's important there. 

What happens when you try?

Share this post


Link to post
Share on other sites

I have the "A" when I test, so I can see the target on the site.

When I test, nothing happens,  except that I can see "site2.php#targetanchor" in the browser.

As I said, link and target on the same page, is OK !

Hmm, now I see the problem!  When I "enter" again, after I see the correct url in the browser, it works!

Any idea how this can be solved?

 
 

Share this post


Link to post
Share on other sites
2 hours ago, web2008 said:

Hmm, now I see the problem!  When I "enter" again, after I see the correct url in the browser, it works!

i'm wondering if it's because it's template based, as opposed to just 2 separate php files.... i'm seeing exactly the same thing.

2 hours ago, web2008 said:

Any idea how this can be solved?

for internal links on the same page, it should work as is; for external pages (e.g linking page 1 to page 2#), then you might need to employ jQuery to scroll to the anchor...

<?php

# External Link Scroller Hook
# Written by brian!

function external_link_scroller_hook($vars)
{
	$validtemplates = array ('homepage');
	if (in_array($vars['templatefile'],$validtemplates)) {
		return <<<HTML
<script>
jQuery ( document ).ready ( function($) {
var hash= window.location.hash
if ( hash == '' || hash == '#' || hash == undefined ) return false;
      var target = $(hash);
      headerHeight = 120;
      target = target.length ? target : $('[name=' + hash.slice(1) +']');
      if (target.length) {
        $('html,body').stop().animate({
          scrollTop: target.offset().top - 125
        }, 'linear');
      }
} );
</script>
HTML;
	}
};
add_hook("ClientAreaHeaderOutput",1,"external_link_scroller_hook");

btw - I didn't write the above jQuery code, I just put it to use in the appropriate hook for your purpose (e.g so that it only gets triggered on specific pages) - possibly it might be ok to run on all pages without issue, but thought better safe than sorry. 🙂

so quickly testing this, I had a link on clientareahome.tpl....

<a href="index.php#target_anchor">Link to external page</a>

and then on homepage.tpl, I had the following anchor....

<h2 id="target_anchor">Lorem Ipsum.</h2> 

when you click on the link, it takes you to the homepage and scrolls to the specified anchor - you can have multiple anchors on the same page and separate links elsewhere to them... also it would work with <a> if you prefer to use that on your anchors, but like bear, i'm used to using other tags with these anchors.

in the above hook, there is a $validtemplates array which contains the template(s) with these anchors where this scroller script should run - just add/edit additional templates to that list when necessary.

Share this post


Link to post
Share on other sites

Hmm, when I add template number 2, this don`t works .

$validtemplates = array ('homepage','template2');

What`s wrong?

Share this post


Link to post
Share on other sites
12 hours ago, web2008 said:

What`s wrong?

is template2 a WHMCS template and that's the template filename ??

I quickly tried the following..

$validtemplates = array ('homepage','custom2');

custom2.tpl is a template used by brian4.php, so on the homepage template, I added the link as before...

<a href="brian4.php#target_anchor">Link to external page</a>

again, custom2 contains Lorem Ipsum text with the anchor used previously within it... clicking on the link in homepage, correctly takes me to the anchor on the custom page... if I disable the hook, the link just takes me to the top of the page..

what are you seeing? is it just taking you to the top of the page ??

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated