-1

Id like this button to open the website in a New window.. Right now it opens in the same page. The code below is what I have in my html. the onclick event will call the setMyAdd function.

<input width="167" type="image" height="45" value="Click me" src="/portals/0/schedappnt.png" id="btn3" onclick="setMyAdd(); return false;" />

This is what I have in my javascript :

<script language="javascript">
var myLink = "";
function hideMe() {
    document.getElementById('btn3').style.visibility='hidden';
}
function setMyAdd() {
    location.href=myLink;
}
function checkForChange() {
    // var buttonSelected=selList.value;
    var buttonSelected = document.getElementById('selList').value; 

    // alert("Option Selected is : " + buttonSelected );
    if (buttonSelected=="optx") {
    myLink = "/HOME/ScheduleanAppointment/tabid/83/Default.aspx";
    document.getElementById('btn3').style.visibility='visible';
    } else {
    myLink = "http://offsiteschedule.zocdoc.com/remote/schedulePopup.aspx?professionalId=0&amp;providerId=10754&amp;locationId=20113&amp;repeatPatient=True";
    document.getElementById('btn3').style.visibility='visible';
    }
}
</script>

<script> 

What do I need to modify so it opens in a new window?

air
  • 21
  • 8
  • 1
    Googling reveals this answer: http://stackoverflow.com/questions/4643958/open-button-in-new-window – hc_ Mar 22 '12 at 21:19

3 Answers3

2

Change location.href = myLink to window.open(myLink);

Aaron
  • 5,137
  • 1
  • 18
  • 20
1
function setMyAdd() {
    window.open(myLink,'Advertisement');
}

The second parameter is the name of the window to open in. If you want your ad to open in the same external window every time, as opposed to spawning endless new windows, then specify the window name. Otherwise Aaron's answer is correct.

zachelrath
  • 842
  • 5
  • 11
0

With the location you take information about the current url. So, with your code you change the url of the current window and the website normally opens in the same window.

You need to use the open() method of the window object to tell the browser to open a new window with url you want. That means


    function setMyAdd()
    {
        window.open(myLink);
    }

You have and other opportunities with the open() method, such as to specify the size of the new window. You may find information here.

Nidis
  • 71
  • 2