Return to previous page in joomla

只谈情不闲聊 提交于 2019-12-12 14:26:27

问题


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.


回答1:


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();



回答2:


I’ve done it this ways:

  1. Install Joomla extension “jumi” @ url http://extensions.joomla.org/extensions/extension/core-enhancements/coding-a-scripts-integration/jumi

  2. Create a html file(ex: back.html) and write following code:

<script>
function goBack()
  {
  window.history.back()
  }
</script>
<input type="button" value="Back" onclick="goBack()" />
  1. Save it into Joomla root directory.

  2. Create a custom module in Joomla and write syntax :

{jumi [back.html]}

  1. Publish this module

I hope it’ll work. thanks



来源:https://stackoverflow.com/questions/12948109/return-to-previous-page-in-joomla

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!