-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?

Async
  • 245
  • 1
  • 4
  • 14

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
  • 61,973
  • 54
  • 229
  • 402
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,521
  • 4
  • 33
  • 57
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
  • 66,980
  • 10
  • 72
  • 94
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!

Async
  • 245
  • 1
  • 4
  • 14