Forum Moderators: open

Message Too Old, No Replies

help with script to set target, write to textarea in another frame

         

illtron

2:37 pm on Apr 5, 2005 (gmt 0)

10+ Year Member



Hi guys, this is probably a simple request, but I'll try to explain it in detail.

I had a thread going a while ago on this. I got it working perfectly, but recently, something weird started happening, and it no longer works.

I have this script...


<script type="text/javascript">

function addClick(){
for (i=0;i<document.links.length;i++){
var hHref=document.links[i].getAttribute("href")
var lTxt=document.links[i].text;
document.links[i].setAttribute("onclick","intercept('"+hHref+"','"+lTxt+"')");

}
}
function intercept(hRef,lTxt){
parent.topframe.document.getElementById('thebox').value=hRef+'\r'+lTxt;
}

</script>

Basically, it writes some stuff to a textarea in another frame when I click it. It had been working great, for the most part (on some links it doesn't work -- no idea why).

Some change on the server that I can't control must have made something screw up recently, however. The script still does its thing, but I also have the <base target="pages"> to open the links in the frame named pages. That stopped working suddenly. No clue why.

So what I want to do now, is add a line to the javascript to handle it.

I tried adding this line:

top.frames['page'].location='href';return true;";

That works, but then the part that writes to the textarea stops working. Can you help me get it to do both?

JAB Creations

2:58 pm on Apr 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



XHTML Strict Valid code for creating new windows ... if thats what your current code is attempting...

HTML

<a href="http://www.example.com" class="externallink" rel="external">Example Site</a>

script-target.js

function externalLinks()
{
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
var map = {external:"_blank", border:"border",mplayer:"mplayer"};
var anchor, i, target;

for (i=0; anchor=anchors[i++];)
if( anchor.getAttribute("href") && (target=map[anchor.getAttribute("rel")]))
anchor.setAttribute("target", target);

}
window.onload = externalLinks;

illtron

3:10 pm on Apr 5, 2005 (gmt 0)

10+ Year Member



I have zero control over the actual formatting of the links. It's all generated by a CMS that I don't control. While I'd love to stick to strict XHTML, it wouldn't really matter because the output from the CMS is far from compliant.

In case you're wondering, this is the hideous code that it spits out at me:


<P CLASS="list">&bull;
<A HREF="/asdf/asdf/asdf.xml"><B>Innovations distinguished old theater</B></A>
<BR> In its early years, the Senate Theater sparkled with first-run films, visits by Hollywood celebrities and top-notch promotions. <BR>
</P>

I could go on for hours about how many things I can find that are awful about that, but it would do me little good, since I don't control it. If I could just put it all in the link, I would. That's why I need to do it with a Javascript.

illtron

11:57 am on Apr 7, 2005 (gmt 0)

10+ Year Member



Can anybody help?