简体   繁体   中英

Using an anchor href in a javascript onclick

I have an href that I would like to use with in an onclick method on the same anchor.

Here's an anchor:

<a href="http://www.google.com" onclick="VideoTrackNLog('Best Practices 3','www.google.com');"><img alt="Best Practice 3"      src="timg/BestPractice3.jpg" style="width: 236px; height: 157px" /> </a></td>

and here's the code the onclick is using:

function VideoTrackNLog(videoname, filename, file) {
        frmVideoTrackNLog.videoname.value = videoname;
        frmVideoTrackNLog.nextpagename.value = filename;
        frmVideoTrackNLog.submit();
        window.open(file,'Video','height=200,width=200,left=190,top=110,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes');
}

The idea is to move the URL in the href to the third parameter in the function. Is there any way this would be possible?

VideoTrackNLog('Best Practices 3','www.google.com', this.href);

Leave the href blank and move the URL to be a function parameter:

<a href=# onclick="VideoTrackNLog('Best Practices 3','www.google.com', 'http://www.google.com');">
    <img alt="Best Practice 3" src="timg/BestPractice3.jpg" style="width: 236px; height: 157px" />
</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM