Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
421 views
in Technique[技术] by (71.8m points)

javascript - Calling keyevent from mouse

I need to emulate a key press with click on a link. The keyboard shortcut CTRL++ must be called with a click on a link, or a similar function.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can't invoke key press with JavaScript.

However, you can control zoom level with JavaScript, here is example for IE and Chrome: http://jsfiddle.net/cMCuz/2/

Edit: now supports Firefox as well.

Required JavaScript:

var _zoomLevel = 100;

function ChangeZoomLevel(diff) {
    _zoomLevel += diff;
    var oDiv = document.getElementById("Contents");
    if (typeof oDiv.style.MozTransform == "string")
        oDiv.style.MozTransform = "scale(" + (_zoomLevel / 100) + ")";
    else if (typeof oDiv.style.zoom == "string")
        oDiv.style.zoom = _zoomLevel  + "%";
}

Sample buttons:

<button type="button" onclick="ChangeZoomLevel(10);">+</button>
<button type="button" onclick="ChangeZoomLevel(-10);">-</button>

This will change the zoom level of whole DIV element, can be changed easily to change zoom level of whole document if required.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...