返回到joomla中的上一页 [英] Return to previous page in joomla
问题描述
我创建了自己的扩展。此扩展程序可以从网站的不同组件和部分访问。
我遇到的问题是,可能有多个不同的URL链接到此扩展。我有一个取消按钮,我无法解决如何获得此按钮链接到以前的URL。
想知道是否有一些内置的joomla像getPreviousURL?找不到任何东西。
编辑:我应该说我仍然想要能够运行我的cancel()方法。例如index.php?option = com_mycomp& task = mycomp.cancel。
如果我明白你的问题,这将有助于你肯定。 Joomla不支持像Javascript这样的东西。
JS
< script&
function goBack()
{
window.history.back()
}
< / script>
HTML
< input type =buttonvalue =Cancelonclick =goBack()/>
back()方法加载历史记录列表中的上一个URL。这是
,与点击后退按钮或history.go(-1)相同。
>根据需要更新答案。
PHP
一个可能性,你可以使用HTTP_REFERER,清除它,并通过PHP回声。
<?php
$ url = htmlspecialchars($ _ SERVER ['HTTP_REFERER']);
$ this-> setRedirect($ url);
?>
如果
- 在浏览器地址栏中输入了网站网址。
- 通过浏览器维护的书签访问了该网站。
$ b
- 安装了安全软件(防病毒/防火墙等),可从所有请求中删除引荐来源网址。
>
如果遇到任何问题,请通知我。
更新答案 - Joomla方法
$ url = JFactory :: getURI();
$ request_url = $ url-> toString();
I have created my own extension. This extension can be accessed from different components and parts of the website.
The problem I have is that there could be a number of different URLs that link to this extension. I have a 'cancel' button and I can't work out how I would get this button to link to the previous URL.
Wondering if there is something built into joomla like getPreviousURL? Couldn't find anything.
EDIT: I should have said that I still want to be able to run my cancel() method. e.g. index.php?option=com_mycomp&task=mycomp.cancel. The cancel() method will then perform a redirection to the previous page.
解决方案If I understand your question right, This will help you out for sure. Joomla does not support something like that but Javascript does.
JS
<script> function goBack() { window.history.back() } </script>
HTML
<input type="button" value="Cancel" onclick="goBack()" />
The back() method loads the previous URL in the history list. This is the same as clicking the Back button or history.go(-1).
Updated Answer as required.
PHP
If JavaScript isn't a possibility, you could use the HTTP_REFERER, sanitize it, and echo it out via PHP.
<?php $url = htmlspecialchars($_SERVER['HTTP_REFERER']); $this->setRedirect($url); ?>
This will not work if
- entered the site URL in browser address bar itself.
- visited the site by a browser-maintained bookmark.
- visited the site as first page in the window/tab.
- has security software installed (antivirus/firewall/etc) which strips the referrer from all requests.
- visited the site programmatically (like, curl) without setting the referrer header (searchbots!).
If you come across any problems let me know.
Update answer - Joomla method
$url = JFactory::getURI(); $request_url = $url->toString();
这篇关于返回到joomla中的上一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!