Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove onlick attribute

Status
Not open for further replies.

Pichdude

Programmer
Aug 24, 2005
66
SE
Hi,

I am wondering if anyone can help me. I have a print version of a page, displayed in a popup window. In this page I want to disable all links. My links have their "action" specified in "onclick".

Is it possible to remove that attributes somehow?

Best regards

Pichdude

 
You can use "getElementsByTagName('a')" to return a collection of all links on the page, and the body "onload" event to run a function... so all you'd need to do is run a function onload to loop over all anchors, setting their "onclick" property to null.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Sure... you can use getElementsByTagName('a') to get a collection of links on the page, then iterate through them all and set the click on them to be null...
Code:
var allLinks = document.getElementsByTagName('a');
for (var loop=0,max=allLinks.length; loop<max; loop++) {
  allLinks[loop].click = null;
}
That should work!

Cheers,
Jeff


[tt]Jeff's Page [!]@[/!] Code Couch
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
You could in the onclick event call blur();

Ordinary Programmer
 
You could in the onclick event call blur();

Assuming the OP wanted to stop people navigating away from his print friendly page, that would not really work.

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thank you all very much!

On this printer friendly page I also would like to "convert" all drop-down lists to only show the selected value as a text, i.e. no selection available. Is this also possible in some nice way?

Best regards

Pichdude
 
I'm assuming that you now have a working solution to remove the onclicks from your page?

Ideally this new requirement would be done server-side (of course). You could also consider using a print style sheet. If you feel it needs to be don using javascript, you will need to look in to DOM traversal to parse each select node into something else (probably a text node).

Read up on methods to access and manipulate the DOM (google will have examples) then if you have specific questions, open up a new thread.

Cheers,
Jeff


[tt]Jeff's Page [!]@[/!] Code Couch
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top