Pentolan
Pentolan

Reputation: 161

how to open url in same page, and also can open in newtab using 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

Upvotes: 2

Views: 2502

Answers (3)

Sagar Munjal
Sagar Munjal

Reputation: 774

Try this

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

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

Upvotes: 0

L. Herrera
L. Herrera

Reputation: 490

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>

Upvotes: 2

user6932427
user6932427

Reputation:

You can use this:

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

Upvotes: 1

Related Questions