Here below a good example on how to implement the useful inArray function for Javascript Arrays:
1 2 3 |
Array.prototype.inArray = function (item) { return (this.indexOf(item) == -1?false:true); } |
If you need to hide the href address a browser usually shows when the mouse is over a particular link you can follow the below example.
1 2 3 |
<a href="page1.html" onMouseOver="window.status='hide link';return true;" onMouseOut="window.status='hide link';return true;"> click here! </a> |
This is useful especially if the href contains special javascript code we want to hide to destination user.
This method is however not suggested because the site will result not clear, and also not fair for the user; avoiding the possibility to evaluate the selected element. A proper and well build site should avoid such tricks.
A clear way to redirect to another website is to use frames. Here below a simple code to put in your index.html:
1 2 3 4 5 6 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb"> <frameset><frame src="http://www.newsite.com"></frame></frameset> </html> |
For a better result a title and a shortcut icon can be added to have a result closer to the final website. Here below the new example code:
1 2 3 4 5 6 7 8 9 10 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb"> <head> <title>WebSite Title</title> <link href="http://www.oldsite.com/images/favicon.ico" rel="shortcut icon" type="image/x-icon" /> </head> <frameset><frame src="http://www.newsite.com"></frame></frameset> </html> |
If you want to redirect your website to a subfolder you can edit (or create) the root file .htaccess using Apache ModRewrite
You can insert the following code:
1 2 3 |
RewriteEngine On RewriteCond %{REQUEST_URI} !^/subfolder RewriteRule ^(.*)$ subfolder/$1 [L] |
This method is useful also to create different installation (and version) of your website in different folders. You can edit then .htaccess file to redirect to one or another installation.
If you want your component function to be accessed by your user prior to login programmatically you can use the following code:
1 2 3 4 5 6 7 8 9 10 |
public function toLogin($msg = "") { if (!$msg) $msg = JText::_('JGLOBAL_YOU_MUST_LOGIN_FIRST'); $app = &JFactory::getApplication(); $uri = JFactory::getURI(); $app->redirect('index.php?option=com_users&view=login&return=' . base64_encode($uri), $msg); return; } |
You can include the function in your helper class
helpers/yourcomponent.php
You can call the function in your MVC code with the following instructions:
1 2 3 4 5 |
$user = JFactory::getUser(); if (!$user->get('id')) { JLoader::register('yourcomponentHelper', JPATH_COMPONENT.'/helpers/yourcomponent.php'); yourcomponentHelper::toLogin(); } |