Tidy up the various shielding (turn) in embedded web development

Source: Internet
Author: User
Tags tagname tidy

Http://imochen.com/tidy-up-the-embedded-web-development-in-a-variety-of-shielding.html

every time you do a client Web page, there will always be a bug that QA put forward, "F5 no screen, right-click menu No screen, how can I select it, I go." You blocked the choice, the contents of this input is not optional, this is not scientific. Look, you see, I can put this picture on the table. " Maybe, later, can not hear this kind of sound again ... Not QA hang up, I have a countermeasure, haha.
Why to block various hotkeys

In the embedded web, to high imitation of the effect of the original, so the Web page of these hotkeys are not so harmonious. Fortunately, there is JS, we can easily kill these unwanted things. But even then, there are problems like that, so let's have a look.

Mask Hotkey Refresh

Generally we think of is F5,ctrl + F5, for the sake of insurance, we put Ctrl + R also added, do not know if you have encountered this situation. Ctrl + N When you reopen a browser under IE opens the current page. This is not a refresh, but it is also categorized into here. Handy to kill this, the code is as follows, KeyCode we can correspond. Anyway, I can't remember, every time I call out to see.

Varevent = e | | Window.Eventvar k = Event.keycode;  if ((Event.ctrlkey = = true && k = = 82) | | (Event.ctrlkey = = true && k = = 78) | | (k = = 116) | | (Event.ctrlkey = = true && k = =) ) { Event.keycode = 0; Event.returnvalue = false; event.cancelbubble = true; return false;}                 
Right click this must be screen off

The right button is divided into flash and on the page. Actually, I didn't do the test. I personally guess that Flash is not in the flow of the document when the right button is independent. However, generally do when the embedded, will flash processing, so this problem is not big. Right-click masking is relatively straightforward.

function(){    return false;};
No drag-dragging

The same simple and drag-and-drop is not explained. When you start dragging, return to false.

function(){    return false;};
Shielded the selected

The user is not allowed to use the mouse to select the content, but if it is on input or textarea, it can be selected,

document.onselectstart = function( e ){    //屏蔽选择,textarea 和 input 除外    var event = e || window.event;    var tagName = ‘‘; try{ tagName = (event.target || event.srcElement).tagName.toLowerCase(); } catch(e){} if( tagName != ‘textarea‘ && tagName != ‘input‘){ return false; }}
A tag force new window
Document.onclick = function (e) {Mask Shift + click Ctrl + clickVarevent = e | | window.    event; var tagName =  "; try{tagName = (event.target | | event.srcelement). Tagname.tolowercase (); } catch (e) {} if ((event.shiftKey || event.ctrlkey) && tagName =  ' a ') {event.keycode = 0; event.returnvalue = FALSE; event.cancelbubble = true; return false;}        

Organize the various masking (go) in embedded web development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.