0. Preface
The expression in the IE address bar is to enter Javascript in the address bar of IE: <code> and execute some functions to dynamically change the parameters of the original page for some purpose, for example, you can open a disabled button or display a hidden image. This article describes how to use the IE Address Bar in detail.
1. Expression Writing Method
Enter Javascript in the address bar of IE: <code> to directly execute the specified code on the current page and immediately see the effect. In addition, <code> can contain multiple statements, or even process control statements such as if/.
The code can be written in two ways:
Javascript: <expression>
The expression is executed and the result of the expression is displayed on the current page.
Javascript: <function>
This expression will execute the specified function, and the display of the current page will not be affected.
So how does ie differentiate whether the code entered in the address bar is a function or expression? In fact, it is very simple. The last statement of the Code ends with the parameter list () and is processed as a function without updating the page display. The last statement of the Code does not end, then it is processed as an expression and the calculation result of the expression is displayed on the current page.
For example, in the address bar of IE, enter:
javascript:1+2
The end of the expression is not a parameter list. Therefore, ie regards 1 + 2 as an expression and the execution result is displayed in the current window:
3
The following code:
javascript:alert("Hello, world!")
The parameter list is at the end of the code, so ie regards it as a function. After execution, a pop-up window will appear, but the content of the webpage will not change. Another example is,
javascript:alert
After the code is executed, the current window displays:
[object]
This is because it is not a parameter list at the end of the code, so IE treats it as an expression. Alert is a method of the window object. It is also counted as "[object]", so the above result is displayed.
Let's look at the following example:
javascript:a=1;b=2;c=3;alert(a+b*c)
Although the Code contains the value assignment expression and the alert () function, the content of the page is not updated because the parameter list is at the end of the Code.
2. convert an expression to a function
We usually want to use the javascript: <function> Format, because the javascript: <expression> changes the page content and makes the modification meaningless. But sometimes we have to use a value expression to achieve the goal, which requires converting the expression into a function for execution. This requires the use of a special function: void (). This function has a parameter.
There are two commonly used conversion methods. One is to use the expression as a parameter of the void () function, for example:
javascript:void(a=1)
After the execution, the page content remains unchanged, but the variable named a in the page has been assigned a value of 1. Another method is to execute the void () function at the end of the entire code, for example:
javascript:a=1;void(0)
The same effect can be achieved.
You can find the hack code of some web pages on the Internet, for example:
javascript:void(document.all.btn1.disabled=false);void(document.all.btn2.disabled=false)
The code in this section executes the void () function for each expression. In fact, there is a simpler method. You only need to execute it once:
javascript:document.all.btn1.disabled=false;document.all.btn2.disabled=false;void(0)
3. Common hack code
Here we will introduce some common hack code segments that can be used flexibly.
3.1 search for elements on the page
The all set of document objects and the getelement series can be used to easily find various elements on the page. If you know the ID of an element (assuming myelement), you can obtain the element in the following two ways:
document.all.myelement
document.getElementById('myelement')
If you do not know the element ID, but you know the HTML Tag Name of the element (assumed as tagname), you can use the following code to obtain all elements with the same tag:
document.getElementsByTagName('TAGNAME')
The return value is a set. You can use the item method of the set to obtain an element. For example, modify the color of the third hyperlink on the page to Green:
javascript:document.getElementsByTagName('A').item(2).style.color="green";void(0)
Change the background color of all TD elements on the page to Red:
javascript:tds=document.getElementsByTagName('TD');for(i=0;i<tds.length;i++){tds.item(i).style.backgroundColor="red";}void(0)
3.2 define functions
You can directly write a function statement in the address bar to define the function. For example, enter the following in the address bar:
javascript:function hello(){alert("Hello!");}
After confirming, enter the following in the address bar again:
javascript:hello()
The pop-up window is displayed.
3.3 display effects
You can set the display ratio of each element through the style. zoom attribute of each element. For example, increase the overall display ratio of the page to 150%:
javascript:document.style.zoom='150%';void(0)
You can use the style. display and style. visibility attributes of each element to display/hide the element. Style. display = "" can display elements, style. display = "none" can hide elements, and hidden elements do not occupy the page location, just as they do not exist at all; style. visibility = false can hide elements, but the hidden elements will keep their original positions and sizes; style. visibility = true: displays elements. For example, hide all images:
javascript:a=document.getElementsByTagName('IMG');for(i=0;i<a.length;i++)a.item(i).style.visibility=false;void(0)
3.4 others
Show all links on the page:
javascript:a=document.getElementsByTagName("A");newwindow=window.open("newwindow");newwindow.document.open();for(i=0;i<a.length;i++){newwindow.document.write("<a href='"+a.item(i).href+"'>"+a.item(i).innerText+"</a><br>");}newwindow.document.close();void(0)