1

My Javascript isnt up to scratch, and im having problems making the link open in the same window rather than a new popup.

In my html I have the following link

<a href="javascript:go_registerParamList('<%=appendStr%>');">Open An Account</a>

The Javascript for the 'go_registerParamList' is:

function go_registerParamList(paramList) {
    if (self.opener == null) {
        var base_window = self;
    } else {
        var base_window = self.opener;
    }
    if (paramList == '') {
        var link = 'https://${accountUrl}?action=go_register_popup&area=SK&button=openregbutton&promo=new_regbutton_en&crea=img&bus_channel=SK';
    } else {
        var link = 'https://${accountUrl}?action=go_register_popup&area=SK&button=openregbutton&promo=new_regbutton_en&crea=img' + '&' + paramList;
    }

    base_window.open(link, "pp_registration", "width=642, height=620, scrollbars=no,  menubar=no, status=no, scrollbars=no, resizable=yes,screenX=5, screenY=5, left=5, top=5");
}

Thanks in advance.

Milap
  • 6,915
  • 8
  • 26
  • 46
Becca
  • 11
  • 1
  • 1
  • 2
  • possible duplicate of http://stackoverflow.com/questions/267704/javascript-open-new-page-in-same-window – TRR Apr 19 '12 at 10:55

5 Answers5

2

JavaScript function :

function openInSameWindow(evt) {
    window.location=evt;
}

HTML hyperlink to open in same window :

<a onclick="openInSameWindow('http://google.com')">Click to open in same window</a>

You can call the function openInSameWindow to open a link in same window.

Subin
  • 3,445
  • 1
  • 34
  • 63
1

The .open() method opens a new window.

Instead, you can just do:

window.location = link;

So:

function go_registerParamList(paramList)
{
    var link;
    if(paramList == '')
    {
        link = 'https://${accountUrl}?action=go_register_popup&area=SK&button=openregbutton&promo=new_regbutton_en&crea=img&bus_channel=SK';
    }
    else
    {
        link = 'https://${accountUrl}?action=go_register_popup&area=SK&button=openregbutton&promo=new_regbutton_en&crea=img&' + paramList;
    }
    window.location = link; 
}
D'Arcy Rittich
  • 167,292
  • 40
  • 290
  • 283
0

use window.open(URL,name,specs,replace) name as "_self "

 window.open(link, "_self" , "width=642, height=620, scrollbars=no,  menubar=no, status=no, scrollbars=no, resizable=yes,screenX=5, screenY=5, left=5, top=5");
MiniduM
  • 176
  • 6
0

You can load a new document into the current window with window.location.assign(link).

See http://www.w3schools.com/jsref/obj_location.asp

CodeClown42
  • 11,194
  • 1
  • 32
  • 67
0
Before you call the base_window.open() method try to alert the link variable. If its 
okay then you may not have problem with that.

Thanks.
Tuhin Subhra Dey
  • 970
  • 6
  • 19