开发者

Making my bookmarklet cross browser

开发者 https://www.devze.com 2023-02-13 17:56 出处:网络
Here is my previous question that is related to this question: Read source code from tabs in IE/Chrome/Firefox.

Here is my previous question that is related to this question: Read source code from tabs in IE/Chrome/Firefox.

I'm not very good at Javascript. I was able to write something that works in Firefox but not in IE or Chrome. Can someone help me get this running under IE, Firefox and Chrome? I am running IE 8, Firefox 3.6.13 and Chrome 6.

My general plan is to get to the page where the passcode is presented, highlight the pass code, click the bookmarklet button on my bookmarks toolbar and the correct decoded passkey will appear in the textbox on the screen.

javascript:(
    function()
    {
        var selectedText = document.getSelection();
        if (selectedText == "")
        {
            alert('Please select the pass code before clicking the button.');
            return;
        }

        var map = [];
        map["0"] = "Z";
        map["1"] = "D";
        map["2"] = "H";
        map["3"] = "K";
        map["4"] = "N";
        map["5"] = "E";
        map["6"] = "H";
        map["7"] = "S";
        map["8"] = "U";
        map["9"] = "W";
        map["A"] = "M";
        ma开发者_Python百科p["B"] = "Q";
        map["C"] = "H";
        map["D"] = "A";
        map["E"] = "P";
        map["F"] = "O";
        var output = "";  

        for (var i = 0; i < selectedText.length; i++)
        {
            output = output + map[selectedText[i]];  
        }

        var frmObject = document.forms[0]; 
        var frmElement = frmObject.elements["txtPassCode"]; 
        frmElement.value = output; 
    }
)();


<script type="text/javascript">
    function GetSelectedText () {
        if (window.getSelection) {        // Firefox, Opera, Google Chrome and Safari
            var range = window.getSelection ();                                        
            alert (range.toString ());
        } 
        else {
            if (document.selection.createRange) {        // Internet Explorer
                var range = document.selection.createRange ();
                alert (range.text);
            }
        }
    }
</script>

source : http://help.dottoro.com/ljcvonpc.php


Try to optimize your code length to under 500 character, current it's more then 900.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号