• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 652
  • Last Modified:

Javascript onClick

Hey All,

I'm trying to get this piece of code to work but I'm having troubles. Any help would be great.

I'm basically targeting a Div that has a Background and trying to get clickable.

I have to user an external JS file cause I only want to target a specific page not the whole site.

I got the style to inject into the div and work. The onclick is giving me a problem. Can anybody see what I'm doing wrong..

Thanks
R.
<!-- Background --->
<div id="background"></div>
<!-- Background end --->
 
<!-- js file--->
document.getElementById('background').onClick="window.location.href='http://www.google.com'";
document.getElementById('background').style.cursor="pointer";
<!-- js file end--->

Open in new window

0
rurth24
Asked:
rurth24
  • 3
  • 2
1 Solution
 
OMC2000Commented:
It should be like the following

<!-- js file--->
function a()
{
window.location.href='http://www.google.com';
}

document.getElementById('background').onclick=a;
document.getElementById('background').style.cursor="pointer";
<!-- js file end--->
0
 
rurth24Author Commented:
Thanks OMC...

One other thing... How do you pop open a new window?
0
 
OMC2000Commented:
function openPopUp()
{
  fwnd = window.open('http://www.google.com', 'PopWindow',
         "width=550,height=500,directories=no,location=no,menubar=no,"
       + "resizable=yes,status=no,titlebar=yes,toolbar=no,scrollbars=yes");
  fwnd.focus();
}

or just

function openPopUp()
{
  fwnd = window.open('http://www.google.com');
  fwnd.focus();
}
0
 
rurth24Author Commented:
Thanks OMC2000 - Good Stuff.
0
 
rurth24Author Commented:
Hey OMC I just posted another question you may be able to help me on. It's connected to this question.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now