Begin with a fresh plain HTML document, and only use HTML and Javascript.
Place on it the hyperlinked word »food»
Upon clicking »food», it should be replaced with »meat and vegetables»
Upon clicking »meat», it should be replaced with »pork with bacon»
Upon clicking »vegetables», it should be replaced with »carrots plus peas»
Upon clicking »pork», it should be replaced with »tough and chewy»
Upon clicking »tough», it should be replaced with »burnt and salty»
(And so on)
I’ve been trying to do this as far as I can, but I’m having escapecode problems.
Here is my code:
<span id="food"><a href="#" onclick="document.getElementById('food').innerHTML='<span id='meat'><a href='#' onclick='var meat = "<span id=&pork&><a href=# onclick=alert(2)>pork</a></span> with bacon"; document.getElementById("meat").innerHTML = meat'>meat</a></span> and <span id='vegetables'><a href='#' onclick='var vegetables = "carrots plus peas"; document.getElementById("vegetables").innerHTML = vegetables'>vegetables</a></span>'">food</a></span>
Here it is in action: http://jsfiddle.net/jshflynn/L6r5rrfx/
I’m sorry it’s not spaced, but that threw up errors.
Notice that »alert(2)» has no delimiting characters around it, I don’t know how to make it say alert(»Hello»).
I feel there must be some recursive way to do this, but I’m not sure.
Thanks in advance. Especially so if you can do the full problem.
Microsoft 365, Microsoft Office for Mac, Microsoft Word, Office 2003, Office 2007, Office 2010, Office 2013, Office 2016, Office 2019, Office 2021 / Office LTSC, Office 365, Office for Mere Mortals, Office Watch /
6 December 2022
Find or change many web links in Word documents using the Replace command, here’s the two tricks – one is good and the other not so effective.
For example, you might need to change the domain name due a corporate restructure or update links so they are secure (https) instead of regular (http) links.
- Reveal the links
- ^d special search code
- Search inside field codes
Reveal the links
The trick is to reveal the links using the View Field Codes shortcut Alt + F9 that will display the underlying link, not the text.
Now the { HYPERLINK …. } field is visible, you can use standard Replace commands to make the changes. For example replace http with https (assuming there’s no ‘http’ references outside field codes).
Be careful with your Replace commands, keep in mind that:
- There’s no way to limit Replace to just inside field codes
- You can use the ^d special search term to find the start of a field, but it has limited value.
- The field code markers { } can’t be used to either Find or Replace.
^d special search code
Using ^d will let you search inside a field to a limited extent. For starters you must have field codes visible (Alt + F9). That makes no sense since if you’re using ^d you’re clearly interested in the contents of field codes but that’s how Microsoft has done it, so we have to live with it.
A way to use ^d is to find certain types of field codes. For example ^d HYPERLINK will find the start of a field followed by a space and the field code HYPERLINK.
Ah ha, you think, I can use wildcards to do clever searches inside field codes. Sorry, Microsoft won’t let you. The ‘Use Wildcards’ option isn’t available with ^d search.
You have to be careful to ensure that your field codes have only the expected number of spaces between elements and parameters are always in the same order.
Search inside field codes
Usually the better way is to ignore the ^d option just Replace strings that can only exist within a field code. For example (with Use Wildcards on) find HYPERLINK*”http: will find any link fields that have http links regardless of the number of characters between the field code and the link parameter.
Use the same trick to find and change field code parameters globally.
After doing a field code Replace it’s a good idea to use Find and manually check the fields to make sure none were missed accidently.
- Putting one document inside another
- Formatting Mail Merge fields
- Show paragraph marks and tabs
- Show field codes gaffe
- Word went weird with field codes
- The Find function in Office – Part 1
In the article below, we will introduce you how to find, change and delete hyperlinks in your Word document.
Hyperlinks in a Word document are very convenient. We can click it to quickly jump to the corresponding web page. Moreover, Word provides a feature which can convert the text into hyperlink automatically. However, sometimes it is not desirable. In one of our article “3 Ways to Prevent Word from Auto Creating Hyperlink“, we show you how to prevent Word from auto convert text into hyperlink. Actually, there is one more way to do that task.
Use “Paste Special” Option
- When you finish copying a text, click “Paste” in “Clipboard” group. For example, we here copy a sample text as below:
- Then choose “Paste Special”.
- In “Paste Special” dialog box, choose “Unformatted Text”.
- And click “OK”.
Now you can see all formats disappear including hyperlinks.
Now let’s see another situation. If you get a long document with thousands of hyperlinks from your colleague, you may want to change or delete some of them.
Below we will first introduce the basic two parts of a hyperlink, and then propose a method to quickly find or locate multiple hyperlinks. And finally, we will give out several methods to modify or remove the hyperlinks in your document.
Two Parts of a Hyperlink
Actually, hyperlink in Word document is a special text, which contains the following two parts:
- Anchored Text: this is the visible and clickable text in a hyperlink. In the example below, the blue words “DataNumen Word Repair” is the “Anchored Text”:
- Link: this refers to the Internet address to which the anchored text links. You cannot see it directly.
Usually, it is the “Anchored Text” that is shown on your document. To view the “Link” part, you can press “Alt + F9”. Below is an example:
Simply press “Alt + F9” again, and you can switch back to “Anchored Text”.
Find All Hyperlinks in a Document
- First, press keyboard shortcuts “Alt+ F9”. You can see all hyperlinks turn into their “Link” parts now.
- Press “Ctrl + H” to open the “Find and Replace” dialog box.
- Click “Find”.
- Then type “^d HYPERLINK” in “Find what” text box.
- Next click “Reading Highlight”.
- Choose “Highlight All”.
Now you can achieve the effect as below:
- Then all the hyperlinks will be highlighted.
- You can also click “Find Next” button to locate each hyperlink one by one.
Change Multiple Hyperlinks in Batch
Let’s say, if you want to migrate your website from http to its secure version, i.e., https. Then you need to change the following link:
https://www.datanumen.com
to its https version:
https://www.datanumen.com
It is obviously not convenient to change all links one by one manually, especially when a file contains thousands of them. Following is the solution:
Since there are two parts in a hyperlink, you need to change both of them.
To change the “Anchored Text” part of the hyperlink:
- Press “Ctrl + H” to open the “Find and Replace” dialog box.
- Type “http://” in “Find what” text box.
- Then type “https://” in “Replace with” text box.
- Click “Replace All”. Now you shall finishing replacing the “Anchored text” part.
To change the “Link” part of the hyperlink:
- Press “Alt + F9” to switch to the “Link” part.
- And press “Ctrl + H” to open the “Find and Replace” dialog box.
- Type “https://www.datanumen.com” in “Find what” text box.
- Type “https://www.datanumen.com” in “Replace with” text box.
- Click “Replace” or “Replace All” button.
Now you have replaced both parts of the hyperlink.
Other than finding or changing hyperlinks, sometimes you may also want to remove them. Following are four methods you can use:
Remove Hyperlinks – Method 1: Right Click
- First thing, select a hyperlink in your Word document.
- Then right click.
- Choose “Remove Hyperlink” option on the menu.
Now you can see the Hyperlink no more. Generally speaking, this is perhaps the most common way to carry out the performance. It’s simple. However, it’s probably not the quickest way to do so when there are thousands of hyperlinks in a document.
Method 2: Use “Format Painter”
In case you have no patience to delete hyperlinks one by one manually, you can check out the following steps.
- First, repeat steps in method 1.
- Next, select the row where the disabled hyperlink lies.
- Now, double click the “Format Painter” icon in “Clipboard” group.
- Then drag your cursor to select the content which contains the rest hyperlinks.
Check the video below:
When you finish the steps above, all hyperlinks shall be gone. Comparing with method 1, this one can be a real time saver. Meanwhile, it’s not that complicated.
Method 3: Use “Replace” Feature
- To use this way, you have to finish all steps in “Steps to Find All Hyperlinks in a Document” first. Make sure you have pressed “Alt + F9” to change to the “Link” view.
- Then in “Find and Replace” dialog box, click “Replace”.
- Type “^d HYPERLINK” in “Find what” text box.
- Finally click “Replace All”.
Method 4: Use Macro in Word
You can also realize deleting hyperlinks in batch by using macro in Word.
- To begin with, press “Alt+ F11” to open “Microsoft Visual Basic for Applications” window.
- Next, double click “This Document” on the left tree view.
- Copy the following code and paste them on the right editing area:
Sub RemoveLinks()
‘ Enumerate all the hyperlinks and remove them in the document
While ThisDocument.Hyperlinks.Count > 0
ThisDocument.Hyperlinks(1).Delete
Wend
End Sub
- Then click the green “Run Sub” button. Or you can simply press “F5”. Both operations can start running the macro.
Comparison of 4 Removal Methods
Methods | Advantages | Disadvantages |
Right Click |
Simple |
You can only remove one hyperlink at a time, which can waste you much time. |
Use “Format Painter” |
1. Simple
2. It’s able to remove multiple hyperlinks in batch, but you need to manually select the related contents. |
You have to click and hold on to scroll down so as to select the whole document which can cost time. |
Use “Replace” Feature |
It’s able to remove multiple hyperlinks in batch. |
You have to remember the codes “^d HYPERLINK”. |
Use Macro in Word |
It’s able to remove multiple hyperlinks in batch. |
You have to use VBA codes which is a bit complex for beginners. |
Deal with Crashed Files
Frequent switching between webpages and documents can result in Word file corruption. To recover word and bring back your files, you need to use the built-in recovery function in Word. Certainly, for better recovery experience, you can take a third-party tool to do it.
Author Introduction:
Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including excel recovery and pdf repair software products. For more information visit www.datanumen.com
Add, Edit or Remove Links or Hyperlinks in Word Documents
by Avantix Learning Team | Updated October 14, 2022
Applies to: Microsoft® Word® 2010, 2013, 2016, 2019, 2021 and 365 (Windows)
You can easily add links or hyperlinks in Microsoft Word documents to add interactivity and make it easy for users to click a link to jump to another location in your document, to another file or web page or even to an email. You can also edit hyperlinks and remove individual hyperlinks or all hyperlinks.
Hyperlinks are often used to:
- Take the user to an external website.
- Take the user to another document or file on the same network or another place in the same document.
- Add a layer of text information over a word or phrase.
Hyperlinks can be displayed as full source URLs or internet addresses such as http://abccompany.ca, as descriptive text, as an image or as a drawing object.
Text as a hyperlink appears underlined and in a color (normally blue) and coordinates with the color theme in your document. In Word, the text color changes automatically after you Ctrl – click hyperlink text. Hyperlink objects do not change color.
Recommended article: 3 Microsoft Word Tricks to Keep Text Together
Do you want to learn more about Word? Check out our virtual classroom or live classroom Word courses >
Insert a hyperlink automatically
You can insert hyperlinks to web sites by typing the address of an existing web page (such as https://abccompany.com) and then pressing Enter or Spacebar. Word will automatically convert the text to a hyperlink using AutoCorrect.
Insert a hyperlink to an existing web page
To insert a hyperlink to an existing file or web page:
- Click where you want to insert a hyperlink or select the text, shape or image you want to use as a hyperlink.
- Click the Insert tab in the Ribbon.
- In the Links group, click Link or Hyperlink. The Insert Hyperlink dialog box appears.
- Under Link to, select Existing File or Web Page.
- If you are using a text hyperlink, enter the descriptive text that will become the link text in the Text to display field.
- In the Address field, enter or choose the address or location where the link should lead. For external references, enter or copy the URL in the Address field.
- Click OK.
You can also press Ctrl + K to insert or edit a hyperlink.
Below is the Hyperlink dialog box:
Insert a hyperlink to an existing file
To insert a hyperlink to an existing file:
- Click where you want to insert a hyperlink or select the text, shape or image you want to use as a hyperlink.
- Click the Insert tab in the Ribbon.
- In the Links group, click Link or Hyperlink. The Insert Hyperlink dialog box appears.
- Under Link to, select Existing File or Web Page.
- If you are using a text hyperlink, enter the descriptive text that will become the link text in the Text to display field.
- In the Look in field, click the down arrow and select the desired location. Navigate to the appropriate drive and folder and then double-click the file.
- Click OK.
Use relative or absolute hyperlink addresses to external files
If you are creating hyperlinks to external files, it’s important to understand the difference between a relative and absolute address. A relative hyperlink uses the address relative to the address of the containing document whereas an absolute hyperlink uses the full address of the destination document including the drive location.
The following example uses an absolute hyperlink address (full path address):
C:DocumentsJanuaryBudget.docx
The following relative hyperlink contains only the relative address or path to a Budget document.
JanuaryBudget.docx
You may want to use a relative hyperlink address or path if you want to move or to copy your files to another location such as another server.
Create a hyperlink using the context menu
Another method of creating or editing hyperlinks is to right-click and use the context menu (you can also press Shift + F10 to display the context menu).
To insert a hyperlink using the context menu:
- Click where you want to insert a hyperlink or select the text, shape or image you want to use as a hyperlink.
- Right-click and choose Link or Hyperlink from the menu. The Insert Hyperlink dialog box appears.
- Select the appropriate button under Link to. If you are creating an external link to a webpage or another document, select Existing File or Web Page. If you are creating an internal link within the document, select Place in This Document.
- If you are using a text hyperlink, enter the descriptive text that will become the link text in the Text to display field.
- In the address field, enter or choose the address or location where the link should lead. For external references, enter or copy the URL in the Address field. For place in the same document, select the appropriate item.
- Click OK.
Insert a hyperlink to a location in the same document
To create a hyperlink to a bookmarked location in the same Word document:
- Select the location, text, image or shape that you want to use as the destination for the hyperlink.
- Click the Insert tab in the Ribbon and in the Links group, click Bookmark. A dialog box appears.
- In the Bookmark name box, type a unique name for the bookmark and then click Add. You may not use spaces in the name of a bookmark.
- Click where you wish to insert a hyperlink or select the text, shape or image you wish to use as a hyperlink.
- Right-click and choose Link or Hyperlink from the menu. The Insert Hyperlink dialog box appears.
- Under Link to, select Place in This Document.
- Select the bookmark that you want to use as the destination hyperlink. Microsoft Word has a default bookmark to jump to the top of the document.
- Click OK.
Below is the Bookmark dialog box in Microsoft Word:
To create a hyperlink to a built-in heading style in the same document:
- Click where you want to insert a hyperlink or select the text, shape or image you want to use as a hyperlink.
- Right-click and choose Link or Hyperlink from the menu. The Insert Hyperlink dialog appears.
- Under Link to, select Place in This Document.
- Select the heading that you want to use as the destination hyperlink. You must have applied built-in heading styles such as Heading 1, Heading 2, etc. in your document (normally through the Styles gallery in the Home tab in the Ribbon).
- If you are using a text hyperlink, enter the descriptive text that will become the link text in the Text to display field.
- Click OK.
In the following example, note both the headings and bookmarks that appear in the Hyperlink dialog box in a Word file that uses the built-in heading styles:
If you create a table of contents in Word using built-in heading styles, it normally contains hyperlinks to headings in the document. For more information, check out this article on Creating a Table of Contents in Microsoft Word.
Edit a hyperlink
To edit a hyperlink:
- Right-click the hyperlink.
- In the context menu, select Edit Hyperlink or Edit Link. The Edit Hyperlink dialog box appears.
- Select the desired options.
- Click OK.
You can also select a hyperlink and press Ctrl + K to edit it.
Add screen tips
You can include screen tip text that appears when you hover your cursor over a hyperlink.
To add screen tip text:
- Place your cursor over the hyperlink to which you want to add a screen tip.
- Right-click and select Edit Hyperlink or Edit Link from the drop-down menu. The Edit Hyperlink dialog appears.
- Click ScreenTip on the top right.
- Type your text in the ScreenTip text box.
- Click OK twice.
Below is the Hyperlink ScreenTip dialog box:
Jump to a hyperlink
Hyperlinks become active when you save your document as a PDF (portable document format) or web page (HTML) file and users will be able to simply click them. However, in Microsoft Word, to jump to a hyperlink, you will need to point to the hyperlink then Ctrl-click the link.
Remove a single hyperlink
To remove a hyperlink:
- Right-click the hyperlink you want to remove.
- In the context menu, select Remove Hyperlink or Remove Link.
Removing all hyperlinks
To remove all hyperlinks:
- Press Ctrl + A to select all.
- Press Ctrl + Shift + F9. All hyperlinks (and other fields) will be converted to text.
Hyperlinks can add a new dimension of interactivity to your Microsoft Word documents and when the files are saved in other formats such as PDF, they become active hyperlinks.
Subscribe to get more articles like this one
Did you find this article helpful? If you would like to receive new articles, JOIN our email list.
More resources
How to Hide Comments in Word (or Display Them)
How to Compress Images in Microsoft Word
3 Strikethrough Shortcuts in Microsoft Word
Related courses
Microsoft Word: Intermediate / Advanced
Microsoft Word: Designing Dynamic Word Documents Using Fields
Microsoft Word: Long Documents Master Class
Microsoft Word: Accessible Word Documents
Microsoft PowerPoint: Intermediate / Advanced
VIEW MORE COURSES >
Our instructor-led courses are delivered in virtual classroom format or at our downtown Toronto location at 18 King Street East, Suite 1400, Toronto, Ontario, Canada (some in-person classroom courses may also be delivered at an alternate downtown Toronto location). Contact us at info@avantixlearning.ca if you’d like to arrange custom instructor-led virtual classroom or onsite training on a date that’s convenient for you.
Copyright 2023 Avantix® Learning
Microsoft, the Microsoft logo, Microsoft Office and related Microsoft applications and logos are registered trademarks of Microsoft Corporation in Canada, US and other countries. All other trademarks are the property of the registered owners.
Avantix Learning |18 King Street East, Suite 1400, Toronto, Ontario, Canada M5C 1C4 | Contact us at info@avantixlearning.ca
Word Link
Allows you to convert specific words into links. Inspired by Drupal module word_link.
This can be useful for crossposting your site’s pages, or for the contextual advertising of your partners (SEO).
Installation
- Latest release
- Bower:
bower install word-link
- NPM:
npm install word-link
Usage
WordLink.apply(text, word|regexp, url, opts);
Argument | Type | Default | Details | |
---|---|---|---|---|
1 | text | String |
Text in which you want to replace the word to word-links. | |
2 | word | String |
A String or RegExp that is to be replaced by word-link. | |
3 | url | String |
A URL to be used to generate a word-link. | |
4 | opts | Dictionary |
(optional) Additional seetings. | |
opts.debug | Boolean |
false |
(optional) Enable debugging mode. Shows a console.log with replaced words. | |
opts.excludedTags | Array |
['H1', 'H2', 'H3', 'H4', 'H5', 'H6'] |
(optional) List of HTML tags to be ignored during replacement. | |
opts.attributes | Object |
{} |
(optional) Additional attributes for a link. |
Returns
Type: String
Text with replaced word-links.
Examples
var WordLink = require('word-link'); var text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
Replace words with a link:
WordLink.apply(text, 'ipsum', 'http://example.com'); // "Lorem <a href="http://example.com">ipsum</a> dolor sit amet, consectetur adipiscing elit."
Find words with regex and replace them with a link:
WordLink.apply(text, '(ipsum|elit)', 'http://example.com'); // "Lorem <a href="http://example.com">ipsum</a> dolor sit amet, consectetur adipiscing <a href="http://example.com">elit</a>."
Word Link understands html. It will ignore existed links and tag attributes:
var html = '<p>Lorem <a href="http://ipsum.com" class="ipsum">ipsum</a> dolor sit amet, consectetur adipiscing elit.</p>'; WordLink.apply(html, 'ipsum', 'http://example.com'); // "<p>Lorem <a href="http://ipsum.com" class="ipsum">ipsum</a> dolor sit amet, consectetur adipiscing elit.</p>"
TODOs
- A setting for tags to be ignored.
- Additional attributes for a link.
- Add tests.
- Nodejs version.