Summary of the problem of path inconsistency in IE and FF browser using WINDOW.LOCATION.HREF jump page

Source: Internet
Author: User

In the Friday, encountered a problem, usually do the project has been using the Firefox browser, the last week to complete a small forum function, because access to the forum is not required for users to log in, only post and reply to the time only need users to log in, so in the system added an interceptor, Post time if not logged in to jump to the login page, after the completion of the function in the Firefox browser under the use of completely no problem, usually very little use of IE browser, so also did not test in IE directly put on the server test, on the server test when the use of Firefox, there is no problem, But one of my colleagues to test when there is a problem, he is the use of Internet Explorer, when it is not necessary to visit the user login to the place also jump to the login page, the function is completely chaotic, has been in the Jump login page, start the first entry will not appear in the login page, Then no matter what button you click is the login page.

For the above problem I began to tune, at the beginning of the thought is my interceptor problem, but in the use of Firefox tuning is absolutely no problem, and then I use IE11 to start testing, debug interceptors, and then found a problem, the first time the interceptor acquired the path is/com/ Action.action, but click on the next connection to become/com/com/action.action, each click on a connection will be in front of the method plus a/com,/com is my struts2 namespace, However, when testing under FF, the Interceptor gets a/com/action.action each time, so it is not a problem to run under FF.

And then began to ask the degree niang how to solve, degree Niang give the answer is IE browser in the resolution WINDOW.LOCATION.HREF = URL, if the URL is relative path, then IE browser parsing is a problem, can not be properly accessed, because then more anxious, So do not think so much, continue to solve the problem on the Internet to find solutions, and then found the following method:

 function   Getcontextpath () { var  pathName = Document.location.pathname;  var  index = PATHNAME.SUBSTR (1). IndexOf ("/"    );  var  result = Pathname.substr (0,index+1)    ;   return   result;  var  path = Getcontextpath (); Window.location.href  = path+ "/com/forumaction_list.do"; 

After using this method in the local test whether IE or Firefox or Google is not a problem, think the problem solved, and then on the server test, but to the server after all the browser is not good to make, is a click on the login page will appear, very depressed there is no, and then continue to find the answer on the Internet, But many are directly copied above the method, there is no substantive role, and then in the blog Park and csdn Post inquiry, but also did not get any useful information, perhaps the great gods are in code/code/code ... and then dragged on to today, Re-read the other people post the reply when asked, it is said that the use of absolute path can be solved, and then a try to embrace the mentality of a change, and then succeeded.

  the solution is to use absolute path, so the above URL can be changed to "/Project name/xxx/xxxaction_xxx.do", tested on the server and local IE and Firefox and Google are all adapted, here record, Memo, Also hope to help other people encounter this problem, the problem of the place to welcome the great God pointed out.

  

Summary of the problem of path inconsistency in IE and FF browser using WINDOW.LOCATION.HREF jump page

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.