1

I would like to append to an anchor the Target=”Popup” or Target=”_self” depending on window name.

I have two windows: Topic and Popup. Based on the current window I want to show the anchor results in one of the two windows.

From Topic window:

<a href=”A” target=”Topic”>
 Or
<a href=”B” target=”Popup”>

From Popup window

<a href=”A” target=”Topic”>
 Or
<a href=”B” target=”_self”>  //don’t show smaller Popup in bigger Popup window

Also the IF statement is not working. The Else condition is never detected?

HTML:

<p>OnClick link to <a href="MoreInformation.htm" onclick="isPopup();">More Information</a>.</p>

JavaScript:

<script type="text/javascript">
    var screenNam= window.name;
    document.getElementById("winName").innerHTML=screenNam;
</script>

<script type="text/javascript">
    var isPopup = function () {

    if (winName = "Popup") {
    var change = document.getElementsByTagName("a");
    change.setAttribute("target", "_self");
    }
    else if (winName = "topic") {
    var change = document.getElementsByTagName('a');
    change.setAttribute('target', '_popup');
    }
    }
</script>
Joe
  • 11
  • 1
  • Just about every line has a problem? Firstly, why do you have two script tags at all? And what's `winName` in the second function, there doesn't seem to be any such variable. And finally, `getElementsByTagName` gets a nodelist, hence the *"...elements"* with an *"s"*, and a nodelist has no `setAttribute` method. – adeneo Feb 18 '16 at 23:35
  • I'm up voting this despite the obvious beginner mistakes as it has practical application and shows some thought. – Yogi Feb 19 '16 at 00:10

0 Answers0