Search code examples
htmlcssjoomlajoomla3.2

Code not work : how to disable the link when the cursor on


May I know what's the problem with this code? I'd try to run it in my index.php in on of joomla module, but the site output is just white.

echo ' < a style="cursor: pointer;" >onclick="location.href='http://example.com/index.php' ">Admin < /a>';

I'd like to make the link for the example.com/index.php not appear / disabled when I put the cursor on the link. I'd try run the code above at the Try It! on w3school.com and it works perfectly, but if I put the code in my file in joomla module, it's not work!

Hope somebody could help me.. thanks in advance


Solution

  • You have an error in your code

    echo ' < a style="cursor: pointer;" >onclick="location.href='http://example.com/index.php' ">Admin < /a>';
    

    The Error

    Parse error: syntax error, unexpected 'http' (T_STRING), expecting ',' or ';' in index.php on line 7
    
    • indentation of element < a> is not correct and should be <a> also applies with the closing tag </a>
    • you have an excess > character near the style="cursor: pointer;"
    • Use window.location.href instead of location.href because you are trying to return the url of the current page.
    • Learn to escape characters as much as possible e.g \"

    The correct php code.

    • echo "<a style='cursor: pointer;' onclick='window.location.href=\"http://example.com/index.php\"'>Admin</a>";