# How to edit a HYPERLINK once created inside a notebook?

When a hyperlink is created in a notebook, there does not seem to be an easy way to actually edit the hyperlink (maybe to correct the URL).

To make some text HYPERLINK, one selects the text using the mouse, then does a right-click and then selects Make HyperLink ..., then a popup menu comes up where one enters the actual URL. Then clicks ok and hyperlink is made.

Now the text becomes a hyperlink.

But how can one bring this menu back up in order to modify the link if needed? Right-clicking on the now hyperlink does not bring up the above menu used to create the hyperlink.

Selecting the cell and typing Ctrl+Shift+E is not really practical, as the cell can be very large and contain many links.

question is: How to bring up the original menu used to make the hyperlink in order to modify any specific link when needed?

-
I don't know any way to bring the dialog box back. When I need to edit a hyperlink, I isolate it into its own cell with command-shift-d (ctrl-shift-d on Windows?) and then type command-shift-e to work on the raw cell. Afterward, I merge the hyperlink back into the cell it was extracted from with command-shift-m. Have you tried that? –  m_goldberg Dec 28 '12 at 2:54
Your isolated hyperlink doesn't look, to me, like it would be difficult to edit. Maybe it's just that I've grown accustomed to such editing. I've done it fairly often. –  m_goldberg Dec 28 '12 at 3:15

To make this working reliable with links in input-cells, links created with Hyperlink or links created with Insert->Hyperlink seems a mess, since all those links have a different nested structure.

Let me start easy: The next should definitely work with links that were created with Insert->Hyperlink (or Ctrl+Shift+H) in text or input cells.

The trick is to use Options when the link is selected. First a simple test: Create a text-cell with a link in it and mark the link. Then press this button

Button["Options", Print@Options[NotebookSelection[SelectedNotebook[]]]]


and you get something like

{ButtonBoxOptions->{
ButtonData->URL[http://www.wweb.de],None},
ButtonNote->http://www.web.de}
}


ButtonData is the link of the target and I haven't tried to find out what the None means. The ButtonNote is the information which is displayed in the status bar of the notebook when you are over the link with the mouse.

Since we can use SetOptions to change those settings the things left to do are to create a button which has the following behavior when pressed

• It extracts the Options of the selected expression.
• It checks whether this is a hyperlink.
• It pops up a DialogInput with the old value of the link which can be edited.
• It sets this new content using SetOptions.

Here we go

Button["Edit Hyperlink",
sel = NotebookSelection[SelectedNotebook[]];
opts = Options[sel];
If[FreeQ[opts, ButtonBoxOptions],
data = ButtonData /. (ButtonBoxOptions /. opts);
Column[{
"Target page",
InputField[Dynamic[url], Expression],
Button["OK", DialogReturn[url]]
}]
];
If[newlink =!= $Canceled && newlink =!=$Failed,
SetOptions[sel,
opts /. (ButtonData -> _) -> (ButtonData -> {newlink,
Last[data]})]
]
]], Method -> "Queued"
]


## Links created with Hyperlink

This works too with the above code, the difficulty is to select the right expression. Try to create an example Hyperlink["A Link", "http://www.wolfram.com"] and now use the arrow-keys to move the cursor inside the link (maybe between the L and the i) and then press Ctrl+. over and over again to extend the selection stepwise. It requires 6 times until I have selected the whole cell.

After hitting 4 times Extend Selection I have selected the right level of the expression and the Options button of my first code-block shows me

{Active->True, ButtonBoxOptions->{