Olegario Posted September 13, 2018 Share Posted September 13, 2018 (edited) This brings up my complete novice question: How make a page go somewhere specific other than the top when it refreshes? Edited September 13, 2018 by cyberRobot Topic extracted from here: https://forums.phpfreaks.com/topic/301689-move-to-top-of-page-after-execution/ Quote Link to comment Share on other sites More sharing options...
Barand Posted September 13, 2018 Share Posted September 13, 2018 First don't hijack other people's posts don't resurrect old posts If you are using PHP, what is shown is completely under your control. If you don't want to show the top half of the page, hide it or don't output it. If you want the whole page to be present but just want to position halfway down then specify the page fragment you want to go to with a "#" in the url. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted September 13, 2018 Share Posted September 13, 2018 5 hours ago, Barand said: If you want the whole page to be present but just want to position halfway down then specify the page fragment you want to go to with a "#" in the url. Here's a quick tutorial on the "#" technique mentioned by Barand: https://www.lifewire.com/adding-internal-links-3466484 Quote Link to comment Share on other sites More sharing options...
Barand Posted September 13, 2018 Share Posted September 13, 2018 Tutorial may be a bit old. With HTML5 named anchor tags not required - just element ids. The sample below uses <h1 id='xxx'> elements. So if you load with, say, http://localhost/sample.html#halfway it will go directly to the halfway element <!DOCTYPE html> <html> <head> <title>Sample</title> <style type='text/css'> div { height:1500px; background-color: gray; padding: 50px; color: white;} </style> </head> <body> <h1 id='top'>Top</h1> <a href='#halfway'>Go to half-way point</a> <div> Some content </div> <h1 id='halfway'>Half-way</h1> <a href='#top'>Go to top of page</a> <div> Some more content </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
Olegario Posted September 13, 2018 Author Share Posted September 13, 2018 12 hours ago, Barand said: First don't hijack other people's posts don't resurrect old posts If you are using PHP, what is shown is completely under your control. If you don't want to show the top half of the page, hide it or don't output it. If you want the whole page to be present but just want to position halfway down then specify the page fragment you want to go to with a "#" in the url. Sorry—I probably did know better—and thanks for moving the post. I am using an internal link but it's having no effect. It works if I put the #backhere in the address bar, though. Here's my code, based on what a colleague gave me. <a id="backhere" name="backhere"></a> <h2>Questions? Need More Information? Contact us at:</h2> <?php if ($_REQUEST['EMail'] != "info") { ?> <FORM ACTION="<?php echo $_SERVER['/example.org/sub/#backhere']; ?>" METHOD="post"> <INPUT TYPE="hidden" NAME="EMail" VALUE="info"> <INPUT TYPE="submit" value="Show E-mail Address"> </FORM> <?php } else { ?> <A HREF="mailto:johndoe@example.org" TITLE="Email John">johndoe@example.org</A> <?php } ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted September 13, 2018 Share Posted September 13, 2018 Why don't you describe to us what you are trying to do. That FORM ACTION looks well dodgy. It looks like you want to go to the "backhere" when the form is submitted, which would give you a form to take you to the "backhere" which would give you a form to take you to the "backhere" and so ad infinitum. Quote Link to comment Share on other sites More sharing options...
Olegario Posted September 13, 2018 Author Share Posted September 13, 2018 The user clicks a "show email address" button. The same page is redrawn, showing the email address (with mailto: link) instead of the button. But the page focus is at the top of the page and the user has to scroll to the bottom to see the email address they just asked for. Note I didn't write this script except I added the internal link stuff. I suspect the colleague who gave me the script didn't write it either. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 13, 2018 Share Posted September 13, 2018 This should do what you are trying to do. <div style="height:1500px; background-color: #ffe;"> Padding to give page more content </div> <h2 id="backhere">Questions? Need More Information? Contact us at:</h2> <?php if ( !isset($_GET['email']) || $_GET['email'] != "info") { ?> <form action="#backhere" method="get"> <input type="hidden" name="email" value="info"> <input type="submit" value="Show e-mail address"> </form> <?php } else { ?> <a href="mailto:johndoe@example.org" title="Email John">johndoe@example.org</a> <?php } ?> However I think using javscript would be a better approach so that everything happens clientside instead of reloading the page. <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type='text/javascript'> $().ready( function() { $("#showemail").click( function() { $(this).css("display","none") $("#email_link").css("display", "inline") }) }) </script> <style type='text/css'> #email_link { display: none; } </style> </head> <body> <div style="height:1500px; background-color: #ffe;"> Padding to give page more content </div> <h2 id="backhere">Questions? Need More Information? Contact us at:</h2> <button id="showemail">Show email address</button> <a id="email_link" href="mailto:johndoe@example.org" title="Email John">johndoe@example.org</a> </body> </html> Quote Link to comment Share on other sites More sharing options...
Olegario Posted September 14, 2018 Author Share Posted September 14, 2018 Thank you for the PHP—it works, of course. There is some weirdness in the address bar: www.example.org/sub/?email=info#backhere The purpose of the PHP is to hide the email address or addresses in the HTML from spambots, until spambots learn to click buttons. It looks like with the javascript, spambots will see the email address in the HTML. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 14, 2018 Share Posted September 14, 2018 5 hours ago, Olegario said: The purpose of the PHP is to hide the email address All the solutions (mine and yours) are using a "mailto" link containing the email address as part of the HTML. If you don't want to expose the johndoe@example.org then send the email with PHP, not a mailto link. Quote Link to comment Share on other sites More sharing options...
Olegario Posted September 14, 2018 Author Share Posted September 14, 2018 The way it was explained to me is that when someone opens the .php file, php processes the file and presents the button but not the email address because of the if/then/else. At this point spambots search the file for email addresses and find none. You and I can press the button to see the address. Kind of like a captcha. 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.