Making Browser Auto-Scroll to Most Recently Submitted Comment - php

I made a comment on a Wordpress blog and I noticed that after I submitted the comment, the top of the browser was flush with the top of my comment. In other words, the web page was auto-scrolled down to the top of my comment.
How can I do this? I am using a comment system with PHP / MySQL.
Thanks in advance,
John

Use an anchor and try to redirect adding the anchor to your link.
header('Location: http://www.example.com/questions/2301455#comment-54564');
should work.
Else you can do it with javascript by setting the hash property of the location object.
location.hash = '#comment-54564';
or using jQuery :
$(location).attr('hash', '#comment-54564');

You can use the following:
<a name="latest_comment">Comment goes here</a>
And then after a user posts a comment, redirect them to:
http://www.your-domain.com/your-uri#latest_comment
Check out this link under the "name attribute" section:
http://www.w3schools.com/html/html_links.asp

Related

Check refering link with php session

I was trying to use the solution posted on How to set a session variable when clicking a <a> link
but I can't get it to work, to only allow access from a specific URL. As example I only want users to access the php page with a link on http://www.examplesite.com en disable direct access to page.php.
I used http_referer, which is working in Firefox, but in IE it isn't working.
I use the link:
<a href="page.php?a=validate">
and on the php page I use the following code:
session_start();
if(isset($_GET['a']) /*you can validate the link here*/){
$_SESSION['link']=$_GET['a'];
}else{
$_SESSION['oldlink']='no previous page';
}
$_SESSION['current']=$_SERVER['PHP_SELF'];
I'm not a star with php and probably missing something.
Could someone help me with this?

url change without anchor tag and refresh using ajax

As per my client need , redirect the page without anchor tag and refresh page ,
and change the URL as per page appearance. I don't know any idea about this.
I can use ajax for page content. but I don't know the URL change option without
page refresh or redirect. how can I do this with ajax j-query. Any one guide me for this issue.thanks advance
sample url
www.samplesite.com/contact.php -> without anchor tag. and page refresh this url need to work on php.
I think you are looking for info about the new HTML5 History API ( pushstate ), this link has a detailed tutorial.
http://diveintohtml5.info/history.html
You can do this using below function.
if(pageurl!=window.location){
window.history.pushState({path:pageurl},'',pageurl);
}
You can use the following javascript functions
window.location.assign('http://www.samplesite.com/contact.php'); // keeps the current page in browser history
window.location.replace('http://www.samplesite.com/contact.php'); // replaces the current page in browser history
window.location = 'http://www.samplesite.com/contact.php'; // the same as assign() and is backward compatible even with the oldest browsers
jsfiddle

Adding Back button for web page loaded within another web page

I have an index.php with two major sections: the navbar and the main-content. The navbar contains links which will load another webpage to the main-content through this jQuery code:
jQuery('#main-content').load('sampleurl');
Some of these web pages contain links to another web page, so I want to add a back button.
I tried using the history.back() and history.go(-1), as well as the $_SERVER['HTTP_REFERER'], but they don't really work in my case.
How will I add the back button in this situation?
You should keep your last viewed page in JavaScript variable or in value of hidden input and then you only need to add button with
jQuery('#main-content').load(old_url);
You must always update your variable when you load your next page via jQuery('#main-content').load('sampleurl');
Try manipulating the javascript location or location.hash
https://developer.mozilla.org/en-US/docs/DOM/window.location
Of course, you need to be able to turn your URL back into the relevant page content too.
In conjunction with both Charlie and Michael's answers, since you are already using jQuery, another option is to include the jQuery Address plugin.
You can implement this idea, by creating a function to read a hash path to load new content. Following this, the content can be navigated by the built-in back + forward buttons.
The only challenge I foresee with this implementation is associating the new content with the hash path.
Good luck!
Just an idea: Add hash to Url whenever you load the page; and then you can use history.back()
$(function(){
if(window.location.hash === 'sampleurl'){
jQuery('#main-content').load('sampleurl', function(){
window.location.hash = 'sampleurl'; //<<-- match with your loaded page;
});
}
});
good luck !

how can i redirect a user to custom url after adding page through add.php (Facebook)

How can I redirect a user to just added page after adding it through add.php?
let's say my url looks like: http://www.facebook.com/add.php?api_key=API_KEY&pages=1
After selecting a page from the select box and clicking 'Add MY_APP_NAME' user is redirected to the wall of the page instead of to freshly added MY_APP.
Notice
I know this type of questions lots of here but i have no found any solution that why i put this question here again.... helps are definitely appreciated
Tried
I tried myself like this using Javascript but seriously not success
<script>
if (window == top) {
top.location.href = 'https://apps.facebook.com/abc/' + document.location.href.replace(/https?:\/\/[^/]*\/?/, '');
}
function addToPage(page_id){
top.location.href = 'http://facebook.com/add.php?api_key=<?php echo C_APP_ID; ?>&pages&perms=publish_stream&page='+page_id;
}
</script>
See Image
https://www.facebook.com/dialog/pagetab?
app_id=APP_ID&
display=popup&
next=https://facebook.com
Using this alternative method you can specify the URL to be redirected to after interacting with the dialog to add an application to your page in the next parameter.
You could try adding that parameter to your request.
Other possible alternatives for the next parameter are -
redirect_url
redirect_uri
Both are used elsewhere when dealing with redirecting users - perhaps one of them will assist you as well...

Making (or passing) an <a href> php variable invisibly on a link

Is there a way to put a php variable in an without it automatically being visible, like a GET variable?
Some click
I want the subsequent browser URL to be www.myphpfile.php (no variable visible).
Thanks for any help.
If I understood you right you want to have something like this:
Start a session and write the contents of $_GET['location'] into, e.g., $_SESSION['location'].
Redirect the user, e.g. header('Location: myfile.php');
If the user changes his location, start at 1
You could create a form for it with method="post" and style the submit button as a normal link using CSS.
That is if I understood you question correctly.
You should use <a href="fake" onclick="window.location=real">, but I prefer use links as The Lord W3C has declared originally.
Edit:
<a href="javascript:goto(nice_url_like_thing)">;

Categories