Forcing a script to open a link in a new window or tab

J

Jeremy Brown

Hello all,
I have a small vanity site that is a member of WebRing. They give you a
script to put on your site that will bring you to the next/previous/random
site in the ring. I know absolutely nothing about scripting and I wish to
force the script open the link in a separate window. Can anyone help me edit
the script so that it will do this?

Also, please forgive the HTML on the page, I am still learning. It will
eventually be all Strict once I get CSS down pat.

Thanks,
Jeremy

Here is my site:
http://jerem43.home.att.net/

Here is the script:

<!--Begin Webring Navigation-->

<script language="javascript" type="text/javascript"
src="http://ss.webring.com/navbar?f=j;y=jerem43;u=defurl">
<!--//

function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
return (new Object());
}

window.open = SymWinOpen;

//-->
</script>

<noscript>
<center>
<table width="33.3%" bgcolor="gray" cellspacing="0" border="2">
<tr>
<td>
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td align="center">
<p class="v-small">This site is a member of WebRing.<br />
To browse visit <a
href="http://ss.webring.com/navbar?f=l;y=jerem43;u=defurl"
target="_blank">Here</a>.
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</noscript>

<!--End Webring Navigation-->
 
S

Steve Pugh

Jeremy Brown said:
I have a small vanity site that is a member of WebRing. They give you a
script to put on your site that will bring you to the next/previous/random
site in the ring. I know absolutely nothing about scripting and I wish to
force the script open the link in a separate window. Can anyone help me edit
the script so that it will do this?

Why not let the user choose to open the links in a new window or tab
if they want to, and to not do so if they don't want to?
Also, please forgive the HTML on the page, I am still learning. It will
eventually be all Strict once I get CSS down pat.

Ah well, the easiest method of forcing a new window (regardless of
whether users want it or not) isn't allowed under the Strict versions
of HTML 4 and XHTML 1 so you have some conflicting goals here.

Here is the script:

<!--Begin Webring Navigation-->

<script language="javascript" type="text/javascript"
src="http://ss.webring.com/navbar?f=j;y=jerem43;u=defurl">
<!--//

Oh good, they're still catering for Netscape 1.0 era browsers that
don't understand script elements. Good for them. ;-)
function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
return (new Object());
}

window.open = SymWinOpen;

//-->
</script>

That looks like it opens in a new window anyway (window.open being a
bit of a clue).

Steve
 
M

Michael Winter

[snip]
<script language="javascript" type="text/javascript"
src="http://ss.webring.com/navbar?f=j;y=jerem43;u=defurl">

As the code is generated by an external site, modifying the markup is
obviously out of the question. However, it is possible to alter the
target attributes after the fact:

function modifyWebringTargets() {
var ring;

if (document.getElementById
&& (ring = document.getElementById('webring'))
&& ring.getElementsByTagName) {
var links = ring.getElementsByTagName('a');

for (var i = 0; i < links.length; ++i) {
links.target = 'webring';
}
}
}

<div id="webring">
<script type="text/javascript"
src="http://ss.webring.com/navba?f=j;y=jerem43;u=defurl">
</script>
</div>

Call the function above after the document's loaded and the links should
be sent to a new window.

[snip]
function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
return (new Object());
}

window.open = SymWinOpen;
[snip]

That looks like it opens in a new window anyway (window.open being a
bit of a clue).

Quite the opposite, actually. That's pop-up blocker code injected by a
Symantec product (though I don't know why it's in the markup, in this case).

If you care to take another look, notice that the open property is being
assigned a reference to a new function, SymWinOpen. All this function
does is return an object to make it look like the call succeeded.

Mike
 
F

freemont

Hello all,
I have a small vanity site that is a member of WebRing. They give you a
script to put on your site that will bring you to the next/previous/random
site in the ring. I know absolutely nothing about scripting and I wish to
force the script open the link in a separate window. Can anyone help me
edit the script so that it will do this?

You could simply add this to the anchor tag:

onclick="window.open(this.href,'_blank');return false;"

.... and that will even validate to XHTML Strict.

HTH
 
J

Jeremy Brown

Thank you for the assistance.
Where in the would I put this script? Does it go into the existing script or
in a new one? As I said earlier, I a ignorant noob at scripting.

Jeremy

--
Visit my Saab & me at:
http://jerem43.home.att.net


Michael Winter said:
[snip]
<script language="javascript" type="text/javascript"
src="http://ss.webring.com/navbar?f=j;y=jerem43;u=defurl">

As the code is generated by an external site, modifying the markup is
obviously out of the question. However, it is possible to alter the target
attributes after the fact:

function modifyWebringTargets() {
var ring;

if (document.getElementById
&& (ring = document.getElementById('webring'))
&& ring.getElementsByTagName) {
var links = ring.getElementsByTagName('a');

for (var i = 0; i < links.length; ++i) {
links.target = 'webring';
}
}
}

<div id="webring">
<script type="text/javascript"
src="http://ss.webring.com/navba?f=j;y=jerem43;u=defurl">
</script>
</div>

Call the function above after the document's loaded and the links should
be sent to a new window.

[snip]
function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
return (new Object());
}

window.open = SymWinOpen;
[snip]

That looks like it opens in a new window anyway (window.open being a
bit of a clue).

Quite the opposite, actually. That's pop-up blocker code injected by a
Symantec product (though I don't know why it's in the markup, in this
case).

If you care to take another look, notice that the open property is being
assigned a reference to a new function, SymWinOpen. All this function does
is return an object to make it look like the call succeeded.

Mike
 
J

Jeremy Brown

Thank you for the help. Where would I put this tag, as I am unfamiliar with
its use. I am a bit slow.

Jeremy
 
M

Michael Winter

Thank you for the assistance.

You're welcome. However, please do not top-post and full-quote to this
group in future.

How do I quote correctly in Usenet?
<http://www.netmeister.org/news/learn2quote2.html>

You might want to investigate OE-QuoteFix
(<http://home.in.tum.de/~jain/software/oe-quotefix/>).

[Corrected this once:]
function modifyWebringTargets() {
var ring;

if (document.getElementById
&& (ring = document.getElementById('webring'))
&& ring.getElementsByTagName) {
var links = ring.getElementsByTagName('a');

for (var i = 0; i < links.length; ++i) {
links.target = 'webring';
}
}
}


Where in the would I put this script?


In a script element as a child of the head element will do:

<head>
<!-- ... -->
<script type="text/javascript">
function modifyWebringTargets() {
/* ... */
}
</script>
<!-- ... -->
</head>

You then have the option of calling the function in response to the load
event:

<body onload="modifyWebringTargets();">

or in a script element at the end of the document:

<!-- ... -->
<script type="text/javascript">
modifyWebringTargets();
</script>
</body>
</html>

The difference between the two is that in the former, the function will
be called after the entire document has finished loading, including any
images and the like. The latter example will call the function once the
script element has been parsed; more or less once all of the markup has
been received.

Hope that helps,
Mike
 
F

freemont

Thank you for the help. Where would I put this tag, as I am unfamiliar
with its use. I am a bit slow.

Just stick that in any anchor tag you have, and it'll open in a new window.

<a onclick="window.open(this.href,'_blank');return false;"
href="a valid link here">text or image</a>

Dunno if it'll help your situation, but there it is. That's what I use.
Not that much more code than target="_blank".
 
F

freemont

Just stick that in any anchor tag you have, and it'll open in a new
window.

<a onclick="window.open(this.href,'_blank');return false;" href="a valid
link here">text or image</a>

Dunno if it'll help your situation, but there it is. That's what I use.
Not that much more code than target="_blank".

Caveat: I would only open new windows when the link is to an external
website OR if it's really necessary. Like, for a smaller popup form or
something. Don't litter the user's monitor with unnecessary windows and/or
tabs.
 
S

Stewart Gordon

Jeremy said:
Hello all,
I have a small vanity site that is a member of WebRing. They give you a
script to put on your site that will bring you to the next/previous/random
site in the ring. I know absolutely nothing about scripting and I wish to
force the script open the link in a separate window. Can anyone help me edit
the script so that it will do this?

You can't force anything on the WWW.

http://webtips.dan.info/force.html

Stewart.

--
-----BEGIN META GEEK CODE BLOCK-----
Version: 1
gc
------END META GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox. Please keep replies on
the 'group where everyone may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top