Forum Moderators: open
I found that (target="_blank") opens a new page for every link the visitor clicks on so soon they could soon have several pages open which is confusing.
So I started using (target="new_page") which just opens up one page. The only problem is that then the visitor clicks on the second link the second page opens up behind the original page that has linked to it. So many people just think the link isn't working.
Is there any any other options? I'd really like it to open just one page but to bring the new page forward.
Apparently CSS has no code for new page opening.
Any help would be great.
On the page you control that opens the links, put something lke this...
<script type="text/javascript">
<!--
function openWithFocus(url) {
var win = window.open(url, 'new_page', '');
win.focus();
return false;
}
-->
</script>
...
<a href="http://somewhere.else/blah.htm"
onclick="return openWithFocus(this.href);">Test</a>
First new page that opens will be in a new window that focuses, each other link after that will open using that same new window and will bring it to the front each time.
For the very small number (~1%) of people who have JS disabled this will still degrade gracefully; it will simply treat the links as normal links and open the pages in the same window.
Jordan
You'd be suprised at what you can do with a bit o' script ;)
This will make all links open in the new window...
<script type="text/javascript">
<!--
function openWithFocus(url) {
var win = window.open(url, 'new_page', '');
win.focus();
return false;
}
function setLinkHandlers() {
var lnks = document.links;
var fnc = function() {
return openWithFocus(this.href);
};
for (var j = 0; j < lnks.length; j++) {
lnks[j].onclick = fnc;
}
}
window.onload = setLinkHandlers;
//-->
</script>
Or if you just want it to work on some links, but don't want to type out the onclick attribute for each one, you can make it like this...
...
for (var j = 0; j < lnks.length; j++) {
if (lnks[j].rel == "new") {
lnks[j].onclick = fnc;
}
}
...
...then make the link you want to open in a new window like...
<a href="http://somewhere.else/blah.htm" rel="new">Test</a>
:)
Jordan