Forum Moderators: open

Message Too Old, No Replies

Best way to set "open to a new page"?

I hope there is another alternative

         

annej

11:26 pm on Oct 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My topic involves the necessity for a lot of links to further information so I'd like to have the outside links open to a new page.

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.

tedster

12:02 am on Oct 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the new pages are under your control, stay with the target="new_page" scheme but make the body tag of each new page read:

<body onLoad="window.focus()">

annej

1:02 am on Oct 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ted,

The new pages are off site and out of my control.

Anne

MonkeeSage

1:41 am on Oct 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you can't control the pages that are being opened, control the opening process! :)

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

annej

4:31 am on Oct 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Jordan, That works great.

Being lazy though, is there any way to just set it for the whole page or better yet the whole site?

I'm getting spoiled by CSS.

Anne

MonkeeSage

5:07 am on Oct 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anne:

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

annej

3:48 am on Oct 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




Jordan,

I like the idea of setting it for the page but with the new script you gave me it's opening in multiple windows. Can we have it open like you showed me in message #4 but be able to set it for the page rather than each link?

Thanks tons,

Anne