Replace link with word

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.

“^d is not a valid special characters for the Find What box or is not supported when the Use Wildcards check box is selected”

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.

Search inside Word field codes with View Field Codes (Alt + F9) ON and Use Wildcards.

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

  1. When you finish copying a text, click “Paste” in “Clipboard” group. For example, we here copy a sample text as below:     Content Containing Multiple Hyperlinks
  2. Then choose “Paste Special”.Click "Paste" then Choose "Paste Special"
  3. In “Paste Special” dialog box, choose “Unformatted Text”.
  4. And click “OK”.Choose "Unformatted Text" ->Click "OK"

Now you can see all formats disappear including hyperlinks.All hyperlinks are gone.

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:

  1. 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”:Words in blue is anchored text.
  2. 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:Hyperlink Including Internet Address

Simply press “Alt + F9” again, and you can switch back to “Anchored Text”.

Find All Hyperlinks in a Document

  1. First, press keyboard shortcuts “Alt+ F9”. You can see all hyperlinks turn into their “Link” parts now.Press "Alt+ F9" to Turn Hyperlinks in Field Codes
  2. Press “Ctrl + H” to open the “Find and Replace” dialog box.
  3. Click “Find”.
  4. Then type “^d HYPERLINK” in “Find what” text box.
  5. Next click “Reading Highlight”.
  6. Choose “Highlight All”.Click "Find" ->Type "^d HYPERLINK" in "Find what" Text Box ->Click "Reading Highlight" ->Choose "Highlight All"

Now you can achieve the effect as below:All hyperlinks have been highlighted.

  1. Then all the hyperlinks will be highlighted.
  2. 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:

  1. Press “Ctrl + H” to open the “Find and Replace” dialog box.
  2. Type “http://” in “Find what” text box.
  3. Then type “https://” in “Replace with” text box.
  4. Click “Replace All”. Now you shall finishing replacing the “Anchored text” part.Type "http://" in "Find what" Text Box ->Type "https://" in "Replace with" Text Box ->Click "Replace All"The anchored text part is replaced while the link part is not.

To change the “Link” part of the hyperlink:

  1. Press “Alt + F9” to switch to the “Link” part.
  2. And press “Ctrl + H” to open the “Find and Replace” dialog box.
  3. Type “https://www.datanumen.com” in “Find what” text box.
  4. Type “https://www.datanumen.com” in “Replace with” text box.
  5. Click “Replace” or “Replace All” button.Type "https://www.datanumen.com" in "Find what" Text Box ->Type "https://www.datanimen.com" in "Replace with" Text Box ->Click "Replace All"The hyperlink has been replaced.

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

  1. First thing, select a hyperlink in your Word document.
  2. Then right click.
  3. Choose “Remove Hyperlink” option on the menu.Select a Hyperlink ->Right Click ->Choose "Remove Hyperlink"

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.

  1. First, repeat steps in method 1.
  2. Next, select the row where the disabled hyperlink lies.
  3. Now, double click the “Format Painter” icon in “Clipboard” group.
  4. Then drag your cursor to select the content which contains the rest hyperlinks.Select the Rest Content Which Contains 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

  1. 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.
  2. Then in “Find and Replace” dialog box, click “Replace”.
  3. Type “^d HYPERLINK” in “Find what” text box.
  4. Finally click “Replace All”.Press "Alt+ F9" ->type "^d HYPERLINK" in "Find what" Text Box ->Click "Replace All"

Method 4: Use Macro in Word

You can also realize deleting hyperlinks in batch by using macro in Word.

  1. To begin with, press “Alt+ F11” to open “Microsoft Visual Basic for Applications” window.
  2. Next, double click “This Document” on the left tree view.Double Click "ThisDocument" on the Left Tree View
  3. 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

  1. Then click the green “Run Sub” button. Or you can simply press “F5”. Both operations can start running the macro.Type the Codes ->Click "Run Sub" Button

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:

  1. Click where you want to insert a hyperlink or select the text, shape or image you want to use as a hyperlink.
  2. Click the Insert tab in the Ribbon.
  3. In the Links group, click Link or Hyperlink. The Insert Hyperlink dialog box appears.
  4. Under Link to, select Existing File or Web Page.
  5. If you are using a text hyperlink, enter the descriptive text that will become the link text in the Text to display field.
  6. 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.
  7. Click OK.

You can also press Ctrl + K to insert or edit a hyperlink.

Below is the Hyperlink dialog box:

Hyperlink dialog box in Microsoft Word to insert or remove link to existing web page or file.

Insert a hyperlink to an existing file

To insert a hyperlink to an existing file:

  1. Click where you want to insert a hyperlink or select the text, shape or image you want to use as a hyperlink.
  2. Click the Insert tab in the Ribbon.
  3. In the Links group, click Link or Hyperlink. The Insert Hyperlink dialog box appears.
  4. Under Link to, select Existing File or Web Page.
  5. If you are using a text hyperlink, enter the descriptive text that will become the link text in the Text to display field.
  6. 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.
  7. 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:

  1. Click where you want to insert a hyperlink or select the text, shape or image you want to use as a hyperlink.
  2. Right-click and choose Link or Hyperlink from the menu. The Insert Hyperlink dialog box appears.
  3. 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.
  4. If you are using a text hyperlink, enter the descriptive text that will become the link text in the Text to display field.
  5. 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.
  6. 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:

  1. Select the location, text, image or shape that you want to use as the destination for the hyperlink.
  2. Click the Insert tab in the Ribbon and in the Links group, click Bookmark. A dialog box appears.
  3. 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.
  4. Click where you wish to insert a hyperlink or select the text, shape or image you wish to use as a hyperlink.
  5. Right-click and choose Link or Hyperlink from the menu. The Insert Hyperlink dialog box appears.
  6. Under Link to, select Place in This Document.
  7. 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.
  8. Click OK.

Below is the Bookmark dialog box in Microsoft Word:

Bookmark dialog box in Microsoft Word to insert hyperlink in the current document.

To create a hyperlink to a built-in heading style in the same document:

  1. Click where you want to insert a hyperlink or select the text, shape or image you want to use as a hyperlink.
  2. Right-click and choose Link or Hyperlink from the menu. The Insert Hyperlink dialog appears.
  3. Under Link to, select Place in This Document.
  4. 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).
  5. If you are using a text hyperlink, enter the descriptive text that will become the link text in the Text to display field.
  6. 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:

Microsoft Word hyperlink dialog box to insert or remove link to bookbmark or heading..

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:

  1. Right-click the hyperlink.
  2. In the context menu, select Edit Hyperlink or Edit Link. The Edit Hyperlink dialog box appears.
  3. Select the desired options.
  4. 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:

  1. Place your cursor over the hyperlink to which you want to add a screen tip.
  2. Right-click and select Edit Hyperlink or Edit Link from the drop-down menu. The Edit Hyperlink dialog appears.
  3. Click ScreenTip on the top right.
  4. Type your text in the ScreenTip text box.
  5. Click OK twice.

Below is the Hyperlink ScreenTip dialog box:

Screen tip dialog box in Microsoft Word for hyperlinks.

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:

  1. Right-click the hyperlink you want to remove.
  2. In the context menu, select Remove Hyperlink or Remove Link.

Removing all hyperlinks

To remove all hyperlinks:

  1. Press Ctrl + A to select all.
  2. 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.

Понравилась статья? Поделить с друзьями:
  • Replace values in excel formulas
  • Replace in word with tab
  • Replace the words in italics in each sentence with a word from the box
  • Replace in word with enter
  • Replace the words in italics below with one word