web2008 Posted July 18, 2019 Share Posted July 18, 2019 Does anyone know how to get anchor from one page to another in WHMCS to works? On the same page it works fine! 0 Quote Link to comment Share on other sites More sharing options...
bear Posted July 18, 2019 Share Posted July 18, 2019 The link needs to include the page as well as the anchor, ie: link-to-page.php#anchor 0 Quote Link to comment Share on other sites More sharing options...
web2008 Posted July 18, 2019 Author Share Posted July 18, 2019 Thanks for the answer, but have tried this and it doesn't work. Also tried "id=" and "name=" 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 18, 2019 Share Posted July 18, 2019 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 0 Quote Link to comment Share on other sites More sharing options...
web2008 Posted July 18, 2019 Author Share Posted July 18, 2019 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> 0 Quote Link to comment Share on other sites More sharing options...
bear Posted July 19, 2019 Share Posted July 19, 2019 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? 0 Quote Link to comment Share on other sites More sharing options...
web2008 Posted July 19, 2019 Author Share Posted July 19, 2019 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? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 19, 2019 Share Posted July 19, 2019 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. 0 Quote Link to comment Share on other sites More sharing options...
web2008 Posted July 19, 2019 Author Share Posted July 19, 2019 Thank you very much brian! - this seems perfect! 0 Quote Link to comment Share on other sites More sharing options...
web2008 Posted August 13, 2019 Author Share Posted August 13, 2019 Hmm, when I add template number 2, this don`t works . $validtemplates = array ('homepage','template2'); What`s wrong? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 14, 2019 Share Posted August 14, 2019 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 ?? 0 Quote Link to comment Share on other sites More sharing options...
web2008 Posted August 29, 2019 Author Share Posted August 29, 2019 Thank you very much brian! - I had something wrong on the site, which made it not work. Everything is OK now! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.