How can I open multiple links using a single anchor tag
You can certainly try this
Demo
<a href="http://www.microsoft.com" target="_blank" onclick="window.open('http://www.google.com'); window.open('http://www.yahoo.com');">Click Here</a>
How to open multiple links from a single hyperlink from anchor tag string in React?
Use regex to parse string and extract links, like this one:
const input = '<a href="https://www.google.com" target="_blank"> National ID </a><a href="https://www.yahoo.com" target="_blank"> National ID </a>';
const regex = /href="(\S*)"/g;
const links = Array.from(input.matchAll(regex), m => m[1]);
How to make a link open multiple pages when clicked
HTML:
<a href="#" class="yourlink">Click Here</a>
JS:
$('a.yourlink').click(function(e) {
e.preventDefault();
window.open('http://yoururl1.com');
window.open('http://yoururl2.com');
});
window.open
also can take additional parameters. See them here: http://www.javascript-coder.com/window-popup/javascript-window-open.phtml
You should also know that window.open is sometimes blocked by popup blockers and/or ad-filters.
Addition from Paul below: This approach also places a dependency on JavaScript being enabled. Not typically a good idea, but sometimes necessary.
Is it possible to put several URL in a href parameter?
The closest you could come would be to:
- Put a default URL in the
href
- List alternative URLs elsewhere (such as in a
data
attribute) - Bind a
click
event handler that runs some JavaScript which prevents the default behaviour and then tests each URL in turn until it finds one that works (or runs out).
Testing would require Ajax which would require either:
- Permission via CORS from each URL you test
- The user of a proxy (which would test availability of the URL to your proxy and not to the browser)
The additional HTTP requests would consume bandwidth (and thus time).
How can I open two pages from a single click without using JavaScript?
Without JavaScript, it's not possible to open two pages by clicking one link unless both pages are framed on the one page that opens from clicking the link. With JS it's trivial:
<p><a href="#" onclick="window.open('http://google.com');
window.open('http://yahoo.com');">Click to open Google and Yahoo</a></p>
Do note that this will be blocked by popup blockers built into web browsers but you are usually notified of this.
Related Topics
Bootstrap 3 to Bootstrap 4 Cols No Longer Horizontally Aligned
Why Doesn't CSS Ellipsis Work in Table Cell
Auto Refresh Code in HTML Using Meta Tags
Css: Vertically Align Div When No Fixed Size of the Div Is Known
Select Second Last Element with CSS
How to Make a Link from a <Td> Table Cell
How to Go Up a Level in the Src Path of a Url in HTML
What Is the Use of Style="Clear:Both"
Text-Overflow: Ellipsis Not Working
Differencebetween <P> and <Div>
What Is Syntax for Selector in CSS for Next Element
Do You Have to Include <Link Rel="Icon" Href="Favicon.Ico" Type="Image/X-Icon" />
How to Allow Only One Radio Button to Be Checked
Hide Textfield Blinking Cursor
Make Div's Height Expand with Its Content
Difference Between ≪Input Type='Submit' /≫ and ≪Button Type='Submit'≫Text≪/Button≫