How can I open a link in a new window using css?
According to the comments:
and how can I specify the size of the window? I want it to be slightly smaller than the original page. also, can I make all the links on the page open in a new smaller window?
You cannot use CSS or HTML for this. You must use JavaScript window.open()
. You can get all the links element.getElementsByTagName()
to a
and you can determine the relationship <T23> attribute : element.className
window.onload = function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
var link = links[i];
if (link.className == 'someClass') {
link.onclick = function() {
window.open(this.href, 'chooseYourName', 'width=600,height=400');
return false;
}
}
}
}
Or, if you are already using jQuery , you can use <T26> to select all links that the specified class has someClass
:
$(document).ready(function() {
$('a.someClass').click(function() {
window.open(this.href, 'chooseYourName', 'width=600,height=400');
return false;
});
});
The window name given in chooseYourName
will make sure all links are opened (re-opened) in the same window. You can also see that you can specify the width and height there.
a source to share
You cannot use CSS for this. You need to use <a target="_blank"></a>
.
Edit: Javascript window.open command.
a source to share