Js: Get the current address. JS: get the sample code of the current URL.
This article mainly introduces the sample code for getting the current URL from js. For more information, see.
The Code is as follows:
<Table width = 100% cellpadding = 0 cellspacing = 0 border = 0>
<Script language = "javascript">
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 language = "javascript">
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 language = "javascript">
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>