Topic: JavaScript Button cannot open another html file. Why?

Hello all,

I am trying to set up an onclick function in Javascript that opens another html file.
Below there are a few examples of the code used and the error messages  they received.

Please note that it must be a button not a hyperlink and also it needs to be the genuine file that opens not a popup window.

I cannot fathom why a simple request to open a file with a button should be such a problem!

Can anyone assist please?

THE FOLLOWING CODE

<form>
<input type="button" name="open file!" value="open file!" onclick="openFile()">
</form>
function openFile() 
{
    file.open(C:\Documents and Settings\Administrator\My Documents\abbtweb\disclaimer.html)
}

GETS ERROR:-
- line 145    Object expected     (button line of code)
...

THE FOLLOWING CODE

<form>
<input type="button" name="open file!" value="open file!" onclick="openFile()">
</form>
function openFile() 
{
    file.open(disclaimer.html)
}

GETS ERROR:-
- line 227    file is undefined      (file.open line of code)
...

THE FOLLOWING CODE

<form>
<input type="button" name="open file!" value="open file!" onclick="openFile()">
</form>
function openFile() 
{
    file.open{C:\Documents and Settings\Administrator\My Documents\abbtweb\disclaimer.html}
}

GETS ERRORS:-
- line 227    char 11 expected ;     (file.open line of code)
- line 145    Object expected     (button line of code)
...

THE FOLLOWING CODE

<form>
<input type="button" name="open file!" value="open file!" onclick="openFile()">
</form>
function openFile() 
{
    window.open(disclaimer.html/)
}

GETS ERRORS:-
- line 227    'disclaimer' is undefined    (window.open line of code)
...

THE FOLLOWING CODE

<form>
<input type="button" name="open file!" value="open file!" onclick="openFile()">
</form>
function openFile() 
{
    window.open(/disclaimer.html/)
}

GETS ERRORS:-
- line 227    Access Denied     (window.open line of code)

Re: JavaScript Button cannot open another html file. Why?

Will this work for you?

    <script language="JavaScript">
    function openFile(){
         document.location.href ="disclaimer.html";
    }
    </script>
   
    <form name="form1">
        <input type="button" name="openfile" value="open file!" onClick='openFile()'>
    </form>

Re: JavaScript Button cannot open another html file. Why?

Thanks Benjamin

I'll give it a go and get back to you.

Thanks again.

Re: JavaScript Button cannot open another html file. Why?

Thanks everyone

The solution - i just needed to put quotes around it

window.open("disclaimer.html")


Thanks again.