How to Make a Link Open Multiple Pages When Clicked

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.

How to make every link open multiple pages when clicked

If I understand you well, you want to add a click event to all your links?
A bit weird request... but here is how you could do it:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>

<a href="https://www.google.com">www.google.com</a>
<a href="https://www.yahoo.com">www.yahoo.com</a>
<a href="https://www.gmail.com">www.gmail.com</a>

<script>

function openWindow(e){
window.open('http://runningrss.com');
}
(function(){

var allAnchors = document.getElementsByTagName('a');
for (var i=0; i<allAnchors.length; i++)
{
var anchor = allAnchors[i]
//First remove existing in case already registered
anchor.removeEventListener('click',openWindow,false);
anchor.addEventListener('click',openWindow,false);
}
}())
</script>

</body>
</html>

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.

How can I open two urls in two tabs in a single click?

Try something like this :

<a id="test" href="#"> CLick </a>
<script type="text/javascript">

document.getElementById("test").onclick = function(){
window.open("http://www.google.com",'_blank');
window.open("http://www.p3php.in",'_blank');
}
</script>

Open multiple links in Chrome at once as new tabs

You can do this in vanilla JavaScript:

<html>
<head>
<script type="text/javascript">
function open_win() {
window.open("http://www.java2s.com/")
window.open("http://www.java2s.com/")
}
</script>
</head>

<body>
<form>
<input type=button value="Open Windows" onclick="open_win()">
</form>
</body>

</html>

Here is a more Chrome-specific implementation (if popup blockers are giving you difficulty):

var linkArray = []; // your links
for (var i = 0; i < linkArray.length; i++) {
// will open each link in the current window
chrome.tabs.create({
url: linkArray[i]
});
}

Here is some documentation: https://developer.chrome.com/extensions/tabs

What javascript would I need to open two web pages at the same time and close the previous tab?

If you want to perform all 3 of those actions at the same time then you may want to create a function that does all three, and then call that function with the onclick event.