REGISTRATION

If you simply play with page’s links through JavaScript, anyone may view the source of the page and recover the links, in order to bypass the form and to navigate to the specific pages. If your intention is: To hide links in order to prevent the user from going anywhere else than to the form target, then just create a page with only the form, its submit button, and nothing else, and especially no links.

Very unclear what you want exactly. You should rewrite the question more clearly and provide more detail.

At a guess though, is this what you are looking for?

UPDATE 1 Edited to include code you posted above. Add a return statement to your member_enable function to return number of rows as mentioned in above answer

UPDATE 2 Sounds like you simply need to retrieve the relevant fields from the DB on page load, loop through them printing out the info and the link, and then, when a disable/enable link is pressed, load a script which enables/disables the account and then returns the admin to the user management page. By reloading the management page, the links will change to the appropriate text as it will be using the updated database values.

Читайте также:  Html шаблон head body

How to disable all href on a web page? Can it be done with javascript?

Technically speaking, you may disable the links by walking through all elements using getElementsByName without jQuery or $(«tagName») with jQuery.

But that’s not what you need, I think.

  • To hide links in order to prevent the user from going anywhere else than to the form target, then just create a page with only the form, its submit button, and nothing else, and especially no links. If you simply play with page’s links through JavaScript, anyone may view the source of the page and recover the links, in order to bypass the form and to navigate to the specific pages.
  • To prevent the user to access anything else on the website (or to access some restricted resources), then use security checks server-side, with automated redirection if the user is not authorized to access a resource. If you’re using a framework, very probably the functionality is already implemented and used to make the difference between authenticated users and guests: authenticated users will be able to access specific resources, while guests will be redirected by the framework to the log-in page. If you simply hide the links on the page, but don’t do any security checks server-side on the «protected» pages, anyone who already used the website before (or knows somebody who did) will know the exact links to enter, bypassing again the form.

Using jQuery this will disable all after page load.

And you just have to run below to enable them again

You could use jQuery to prevent the default event listener for the click event while you want the links to be disabled, then unbind it when the user is allowed to navigate again.

//remove click ability $("a").click(function(e)); //reset $("a").unbind('click'); 

Though this would need some other work if you have some click listeners you want to keep active on certain links etc.

Html- how to disable ?, )

 if(condition) disableLink(); else showLink(); function disableLink() < document.getElementById('Link1').disabled=true; document.getElementById('Link1').removeAttribute('href'); document.getElementById('Link1').style.textDecoration = 'none'; document.getElementById('Link1').style.cursor = 'default'; >function showLink() < document.getElementById('Link1').disabled=false; //assign href dynamically document.getElementById('Link1').href = "somepage.html"; document.getElementById("Link1").style.textDecoration = "underline"; document.getElementById("Link1").style.cursor = "hand"; >

You can disable the link by setting the disabled attribute (not valid on anchor elements, though it works in some cases).

Test setup for disabled attribute on anchors: http://jsfiddle.net/TgjnM/

Preferably, you can remove the link altogether and replace it with the text it contains. To replace the link with plain text, you would set the innerHTML of mydiv to the text (thus removing the hyperlink).

If the link can be toggled on/off, consider a form element (not a hyperlink) as @Oleg V. Volkov suggested in the comments. If it is a one-time decision (i.e. it won’t be happening multiple times per page), I would replace the link with text.

Based on logged on user i need to disable or enable..

In that case, I would render the page differently on the server, not in the web browser.

No, it isn’t possible. However, you can use rewrite rules to change the request URL such that it looks something like: banner.php/1234

A different approach would be to use a post request with a form, like so:

In this case, only the button is visible. The button can be styled like a link,

You can do this using .htaccess file, add following code

Your .htaccess file

options -multiviews RewriteEngine On RewriteBase / RewriteRule ^banner/([^/.]+)?$ banner.php?packageID=$1&%

in simple words it is not possible to hide that value from URL at all. Below are other approaches for you:

Use better URL like banner/1234

User title value instead of Id like banner/banner-title , I would suggest this.

Javascript — How to disable HTML links, You can disable the HTML link as given below: .disabled-link

Источник

Disabling of hyperlink can be done by the help of Javascript, but can anyone tell me the code, how to disable a hyperlink by the help of php coding. In the web page, it is desired that when a user signs in as an administrator, he could access the hyperlink, otherwise this hyperlink should be visible to other users as disabled hyperlink. Is it possible by the help of php coding? (server side validation). I am new in PHP coding, and do not want to use javascript coding. Is this could be done by the help of html coding or using css. I hope, I shall be soon getting response from the talented coding experts of php and html coding.

  • 7 Contributors
  • 12 Replies
  • 2K Views
  • 3 Days Discussion Span
  • Latest Post 13 Years Ago Latest Post by surenkumar

Add ‘class’ or ‘id’ for this anchor.

And you can change in css:

If I understand right you’d like a link that doesn’t go anywhere if they’re not an admin.
Something like

with something like this in your css

All 12 Replies

Hi fobos. Thanks for providing the code. It is nice code, but I need a little more information regarding disabling of hyper link. I want that its color would become gray when user clicks on it and it should not perform any action of being redirected to link page. It should give a feeling to user that this is a proper link, but he is not having access right to use it. This can be done by using javascript, but I need server side validation. Hope you would have got my point. Again thanks for your help.

If I understand right you’d like a link that doesn’t go anywhere if they’re not an admin.
Something like

Hi. i dont know how to post a thread. i really need help with registration form.
any one there please check this my form. its not uploading an image and when i check if the user exists. it is still performing validations.

' data-bs-template=' '>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ' data-bs-template=' '>http://www.w3.org/1999/xhtml">   "; > elseif($unamelength!=8) < echo "Username should be eight characters long"; > elseif($pass=="") < echo "Password should be entered compulsory"; > elseif(is_numeric($pass)) < echo "Password should contain numbers and characters"; > elseif($passlength <6) < echo "Password should be greater than 6 characters"; > elseif($repass=="") < echo "Please enter Confirm Password"; > elseif($repass!=$pass) < echo "Confirm password does NOT match password"; > elseif(preg_match("/^[a-zA-Z]\w+(\.\w+)*\@\w+(\.[0-9a-zA-Z]+)*\.[a-zA-Z]$/", $_GET["email"]) === 0) < $errEmail = '

Email must comply with this mask: chars(.chars)@chars(.chars).chars(2-4)

'; > elseif(preg_match("/^5-7-8$/", $_GET["date"]) === 0) < $errDob = '

Date must comply with this mask: YYYY-MM-DD

'; > elseif($fname=="") < echo "
First Name should be entered compulsory"; > elseif($lname=="") < echo "
Last Name should be entered compulsory"; > // Address must be word characters only elseif(preg_match("/^[a-zA-Z0-9 _. \"\']+$/", $_GET["address"]) === 0) < $errAddress = '

Address must be only letters, numbers or one of the following ". , : /"

'; > elseif($country=="Select Country") echo "
Please ensure that the country is selected"; elseif($country!="Select Country") < if($country=="Jamaica") $ja_sel="selected"; elseif($country=="Usa") $usa_sel="selected"; elseif($country=="Japan") $jap_sel="selected"; if($gender=="") echo "
Select Gender!"; elseif($gender!="") < if($gender=="Male") $maletype="checked"; elseif($gender=="Female") $femaletype="checked"; if($city=="Select City") echo "
Ensure that the city is selected!"; elseif($city!="Select City") if($city=="Kingston") $kgn_sel="selected"; elseif($city=="St Catherine") $cath_sel="selected"; elseif($city=="St Mary") $mar_sel="selected"; elseif($city=="St Andrew") $and_sel="selected"; if($term=="") echo "
Terms and conditions must be checked!"; elseif($term!="") < if($term=="agree") $agreetype="checked"; elseif($term=="disagree"); >> > //-----------------CONNNECTING TO THE TABLES IN THE DATABASE------------ if ($ans==1) < connectdatabase(); $result=mysql_query("select * from users where Username='$uname'"); $numofrows=mysql_num_rows($result); if ($numofrows>0)< echo "
Username already exist"; > elseif($numofrows==0) < $sqlinsert="insert into users(Username,Password,Email,Gender,Birth_date,Fname,Lname,Address,City,Country,Image) values('$uname','$pass','$errEmail','$gender','$errDob','$fname','$lname','$errAddress','$city','$country','$picture')"; mysql_query($sqlinsert) or die("cannot insert record"); echo "Registration Successful"; >> else echo "please try again"; > ?>
Registration Form User Name " /> Create-Password " /> Confirm Password " /> Email: "> Gender />Male />Female Upload Image Birth Date: "> First Name: "> Last Name: "> Address: "> City Country Terms and Conditions /> Agree />Disagree

Источник

The print CSS is being customized, and it is noticed that links are being printed with both the link and the value. However, it is suggested that it is better to completely hide the links as users may get confused by such things.

My webpage has a menu specifically designed for users who are logged in.

I am adding this page to my website’s other pages, but I wish to restrict access to the links only to logged-in users.

Is there a way to deactivate every link present on the page using a PHP variable named = ‘no’ ?

I’m uncertain about how to turn off the links.

Can disable links be modified using either CSS or JavaScript?

Use javascript:void(0); to prevent redirection while preserving the CSS of the link. When clicked, the link will not redirect.

To simplify things, why not substitute the hyperlinks with regular text? If my comprehension is accurate, this should be a straightforward solution.

Concealing the links entirely is preferable since regular users are often perplexed by them, as previously stated.

To eliminate all href from a tags, ensure to place this code after all a tags, but only if the php var is no; otherwise, the code won’t function.

 var x=document.getElementsByTagName("a");for (i=0;i'; > ?>

Prior to output, processing must be done as PHP cannot deactivate href dynamically for an existing DOM element.

If you are generating the links output using PHP, you have the option to implement a solution such as:

If the PHP script returns a negative response, consider using AJAX to disable the links on your pages through JavaScript.

Prevent href=»#» link from changing the URL hash, You should (almost) never have href=»#». It is a link to an undefined anchor (which will be the top of the page). People who use it normally do so because they want to dangle JavaScript off it. If you are going to have a link, then it should point to somewhere useful.

Disable «a» href tag using code behind(c#) in asp.net 4.0

I have attempted various methods to deactivate my for specific situations.

//codebehind if(condition) < aTag.Disabled.Equals(true); >//.aspx page 

The issue isn’t resolved, and I’m unsure of the cause. If anyone has a more effective solution, I would greatly appreciate it. Thank you.

Utilizing javascript:void(0); can terminate the link.

The disabled html attribute can be attempted, although it may not be effective for links.

aTag.Attributes.Add("disabled","disabled"); 

An update has been made stating that the «disabled» function is ineffective when it comes to links.

Perhaps the solution is to eliminate the href’s value.

Attempt to assign the href attribute to javascript:void(0).

To reference aTag in javascript, it is necessary to set client mode to static. Alternatively, if it is not needed, it can be removed.

Verify it on the server by using the following code: if condition < aTag.Enabled == false >.

Javascript — Disabled href tag, There is no disabled attribute for hyperlinks. If you don’t want something to be linked then you’ll need to remove the tag altogether. Alternatively you can remove its href attribute — though this has other UX and Accessibility issues as noted in the comments below so is not recommended. …

I attempted to use style=’border: none;’ , but it proved to be ineffective.

Take out outline from :focus .

To ensure that all users can navigate your website easily, it’s important to include a clear indication of when a link has been focused on due to accessibility concerns. Without this, certain users may encounter difficulties while browsing your site.

For Instance,

Источник

Оцените статью