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.
<a href="http://www.example.com" onclick="myFunction()">
Related Topics
How to Escape HTML Special Chars in JavaScript
Get Cursor Position (In Characters) Within a Text Input Field
Adjust Width and Height of Iframe to Fit With Content in It
Height Equal to Dynamic Width (Css Fluid Layout)
In What Situations Would Ajax Long/Short Polling Be Preferred Over Html5 Websockets
How to Check File Mime Type With JavaScript Before Upload
Creating a Div Element in Jquery
How to Specify a Suggested Filename When Using Data: Uri
How to Make a ≪Button≫ Not Submit a Form
How to Programmatically Set the Value of a Select Box Element Using JavaScript
Capture Iframe Load Complete Event
Zoom in on a Point (Using Scale and Translate)
Find the Closest Ancestor Element That Has a Specific Class
After Submitting a Post Form Open a New Window Showing the Result