[thelist] Javascript help redux

Jake Stetser jake.stetser at headhunter.net
Wed Dec 27 16:05:38 CST 2000


So I figured out what's below the line, but does anyone know how to
counteract someone renaming a window on you?

i.e., I pop open a window using target="jump" I assume that means
window.name='jump' for the new window.

Camworld.com renames the window using window.name='mainWindow';

Now how do I access the properties of the window I just opened, without
knowing the new name of the window, if it has one, so I can set it back to
the value _I_ gave it? 

I don't want usurpers breaking the nifty window opening preferences script.
:)
============================
so I have this javascript function,  developed mainly by Jeff. Thanks Jeff!

function setTarget(target, name) {
	setCookie('linkPref',target);
    for(a = 0; a < document.links.length; a++)
    {
    	if(name == null || document.links[a].name == name) {
        	document.links[a].target = target;
		}
    }
}

Nice, isn't it? I have the page set a) to call the function onload to set
the preference stored in the cookie...

body onload="setTarget(getCookie('linkPref'),'external')"

And there are some images that people can click to set their preference...

<a name="target" id="target_self"
href="javascript:setTarget('_self','external')" accesskey="S"><img
title="Open links in this window" src="/images/same_window.gif" width="20"
height="20" border="0" alt="this window" /></a>
						<a name="target"
id="target_same" href="javascript:setTarget('jump','external')"
accesskey="O"><img title="Open all links in the same new window"
src="/one_new.gif" width="20" height="20" border="0" alt="new window" /></a>
						<a name="target"
id="target_blank" href="javascript:setTarget('_blank','external')"
accesskey="N"><img title="Open each link in a new window"
src="/images/all_new.gif" width="20" height="20" border="0" alt="new window
for each link" /></a>

Finally, here are some links, the external ones the function is supposed to
affect. 

<strong class="identifierOff">&gt;</strong> <a href="http://sabren.net/"
name="external">Sabren.net</a><br />
<strong class="identifierOff">&gt;</strong> <a href="http://camworld.com/"
name="external">Camworld</a><br />
<strong class="identifierOff">&gt;</strong> <a href="http://evolt.org/"
name="external">Evolt!</a><br />

What's my problem? Well, when I select the "Open links in one window"
option, the first link I click opens in the correct window. The second link
I click opens in the correct window. The third opens in a new window!

Well, after some testing, it appears I can click the sabren.net link and the
evolt.org link as many times as I want, but as soon as I click the camworld
link, the next page opens in a new window... I wonder if it has something to
do with camworld...

AHH! That doity rat renames the window! Early on in the page, he uses the
code window.name = 'mainWindow';

Hrmph. 




More information about the thelist mailing list