最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Javascript - opening a link - Stack Overflow

programmeradmin5浏览0评论

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.

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.

Share Improve this question edited Apr 20, 2012 at 10:20 Milap 7,2298 gold badges27 silver badges47 bronze badges asked Apr 19, 2012 at 10:52 BeccaBecca 111 gold badge1 silver badge2 bronze badges 1
  • possible duplicate of stackoverflow./questions/267704/… – TRR Commented Apr 19, 2012 at 10:55
Add a ment  | 

5 Answers 5

Reset to default 2

JavaScript function :

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

HTML hyperlink to open in same window :

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

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

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; 
}

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");

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

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

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.
发布评论

评论列表(0)

  1. 暂无评论