如何在同一页面中打开网址,也可以使用javascript在新标签页中打开

如何在同一页面中打开网址,也可以使用javascript在新标签页中打开

问题描述:

it possible? how to do that? for now i just can open in same window

<div style='cursor: pointer;' onclick="window.open('dailyreport', '_self');">Daily Report</div>

that just for open in same window, if i change like this

<div style='cursor: pointer;' onclick="window.open('dailyreport', '_blank');">Daily Report</div>

open in newtab.

how to do if i want to open in same window, also can open in newtab if i want it? thanks

I hope I understand your question with this:

<script type='text/javascript'>
    function Print_Report() {
        if(confirm("Do you want open on a new tab?") == true) {
            window.open('url.php', '_blank');
        } else {
            window.open('url.php', '_self');
        }
    }
</script>

<div style='cursor: pointer;' onclick='Print_Report();'>Daily Report</div>

EDIT:

Other possible option is create another div for that:

<script type='text/javascript'>
    function Print_Report() {
        window.open('url.php', '_self');
    }

    function Print_ReportNewTab() {
        window.open('url.php', '_blank');
    }
</script>

<div style='cursor: pointer;' onclick='Print_Report();'>Daily Report</div>
<div style='cursor: pointer;' onclick='Print_ReportNewTab();'>Daily Report</div>

You can use this:

window.open("http://www.google.com",'myTab');
window.location.href = "http://www.google.com";

Try this

window.open("www.youraddress.com","_self")

This is link to the Mozilla developer docs on Web API Window.open