-1

I want something like this:

function goTo (String string)
{
    window.location.href = string;
}

and access it with button click.. like:

<button class="button" onClick="home(" My target url/file directory ")">Test</button>

Is it possible?

Unixyz
  • 225
  • 1
  • 4
  • 13

4 Answers4

2

You can't have double quotes inside double quotes, use single quotes instead:

<button class="button" onClick="home(' My target url/file directory ')">Test</button>
jcubic
  • 56,835
  • 46
  • 206
  • 357
2

You're on the right path:

function goTo(url) {
  window.location.href = url;
}
<button onClick="goTo('http://www.stackoverflow.com')">Test</button>
moffeltje
  • 4,264
  • 4
  • 29
  • 52
1

yes, just that you need to tweak your code a little bit, fiddle

Function arguments doesn't need a type

function goTo ( string)
{
    window.location.href = string;
}

Finally, you need to escape inner double quotes

<button class="button" onClick="goTo ('My target url/file directory')">Test</button>
gurvinder372
  • 64,240
  • 8
  • 67
  • 88
0

Okay so I got it working this way:

function locationUrl (string) {
    window.location.href = string;
}

<button class="button" onClick="locationUrl(&quot;#&quot;)">Test</button>

Thanks to you all!

Unixyz
  • 225
  • 1
  • 4
  • 13