I have listed projects in main work page, If i click on the project it will direct to work page where details have been displayed,If i click on the back button its is redirecting main work page.I want back button should redirect the previous project please help.
For your back button to redirect you to the previous project, you need to change the present HTML from
BACK
to :
BACK
You will have to do this dynamically by calculating the page numbers in the href as $_GET['page'] - 1
<? $page = (int) $_GET['page']; $back = $_GET['page'] - 1;
print 'BACK';
?>
The back button in my browser is working as-designed on your site: it takes me to the previous webpage I was on.
Websites cannot (easily) alter the behaviour of the browser back button in order to keep the user in-control. You can't (easily) use the back button to navigate through a website (if I understand your question correctly).
why not change the back button client-side?
<a href='#' id='backBtn'>Back</a>
And in JS:
document.getElementById('backBtn').onclick = function()
{
history.back();
};
If all you want is for the back btn to behave like the browser back button?
Related
I know there is a tag to read the sessionsmarty.session.. tag but is there tag for destroying the session, like smarty.session.destroy?
What I want is when I click on menu button Data to destroy all stored sessions and start over with clean session.
This is the button that I have
<a href="/data.php" {if $smarty.server.PHP_SELF == "/data.php"}class="selected"{/if}><span>{php}echo __('Data'){/php}</span></a>
I have session destroy in my PHP code where I detect if there is addition parameter in the URL to destroy it and re-load the page with clean session but I don't know if there is such thing for buttons. This is my php
if((isset($_GET['data'])) {
session_destroy();
header("Location: data.php");
exit;
}
So, if user is on https://example.com/data.php?data and refresh the page will load https://example.com/data.php with destroyed sessions.
How can I accomplish the same with the menu button click?
Here is one quick (perhaps ugly) "hack". You can change your button like this:
<a href="/data.php?data" {if $smarty.server.PHP_SELF == "/data.php?data"}class="selected"{/if}><span>{php}echo __('Data'){/php}</span></a>
This way you actually will pass the same parameter with the URL (like the one you expect in the if condition) and when you click on the button it will be cleaned and redirected to /data.php from the if condition. You will get one extra redirect on the button click.
I have a Website with 2 pages and therefore I have 2 buttons to switch the page.
I want to change the Website only if it´s needed, so for example If I´m using page 1 and I click the button for page 1 it shouldn´t reload.
The first step I guess is to check the URL
$link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
but with research i couldn´t go further :/
Has anyone a idea how I can do that - it´s not important for me to use tag.
You can do something like this:
<button onclick="switchPage(this)" data-page="index.php">page 1</button>
<button onclick="switchPage(this)" data-page="test.php">page 2</button>
In order to redirect to the desired page, you can simply check the URL and the button pressed using JavaScript or jQuery.
Here is an example using JavaScript :
function switchPage(page) {
let pageName = page.dataset.page;
let path = location.href.split("/").slice(-1);
if(pageName != path) {
window.location.href=pageName;
}
}
I am new to php. I have Form on a page with a button that once clicked it pops up another sub page :
onclick="newPopup('page2.php','750','500')
page2.php has another button, I want to be able to redirect the Main Page to another url using this pop-up.
How can I do this?
If you want to redirect the main page on a button click in the popup, you need to do this with JS, not PHP.
Add this to the button in the popup:
onclick="window.opener.location.href='someurl.php'";
From a popup, you can access the page/window that opened the popup with: window.opener. This means that you also can call functions on the main page: window.opener.someFunctionOnTheMainPage().
On click of button, you can execute below JavaScript:
window.opener.location.href = 'new URL';
This will redirect your parent page to the new URL.
I’ve been battling with this for hours, I wonder if anyone can help.
I want to make a redirect script which first actions a link. I have a link generated by php which deletes the current user’s avatar. This link works (user avatar is deleted) however the link itself doesn’t lead anywhere, it just reloads whichever page it is launched from (I haven’t quite worked out how yet, I presume this is a feature of wordpress/buddypress which I am using). My aim is that on arrival to a particular page (page1.php), the delete avatar link is automatically actioned, and then the user is redirected to another page. So:
1) User arrives at page1.php
2) Script fires this link :
<a href="<?php if ( bp_get_user_has_avatar() ) : print 'mysite.net/members/'; echo userpro_profile_data('user_login', $user_id2); print '/'; bp_avatar_delete_link(); else : 'something-else.php'; endif; ?>"></a
3) User redirected to page2.php
I guess there may be some way to do this in javascript/ajax but I hardly use it so not really sure how. I’m struggling to get it to work in php also. Any help would be really appreciated.
Thanks.
You can redirect the page via Javascript using Location API:
<script type="text/javascript">
window.location = <?= $new_location ?>;
</script>
Or you can do it in PHP after performing required operations using code like this:
header("Location: {$new_location}");
But notice that if you redirecting via headers you should not echo enything to the page before it.
Or you can use wp_redirect() if youre doing it in Wordpress.
i have simple coding problem. i have created a page with textbox and share button. the page also contains one Points up button.
i had a problem with that points up button that when the user click on that button and refresh the page ... a window ask for resend of information
for that i have used following code which works fine.
`header('Location: samepageurl.php');
exit;`
but the problem with above code is when user scroll down page and click the button. the page automatically scrolls up. and user have to manually scroll it down.
what i want is the page should refresh but it should be on the same location where it was.
if the problem is still unclear please refer the following images
You can set a fragment identifier.
eg:
<a name="points_up"></a> <!-- this needs to be near that button, the page will scroll exactly where the element is -->
and redirect him to:
header('Location: samepageurl.php#points_up');
die;
Mihai answer is correct, but as you said that fragment identifier is not working because each user has points up button, you can pass user id as a fragment identifier and make a hidden(display : none;) <a> tag and pass the user id in front of each user...
Like this:
You can set a prefix before a user id too (optional)
<a name="pu12345" style="display: none;"></a>
<?php
header('Location: whatever.php#pu12345');
exit;
?>
You can send the request via ajax instead relying on the normal form submission. That will not affect the scrolling of the current page.
Add this line at the bottom of your page before the the <\body> tag
<button id="PageRefresh">Refresh a Page in jQuery</button>
<script type="text/javascript">
$('#PageRefresh').click(function() {
location.reload();
});
</script>