Summary of the inconsistency between paths in IE and FF browsers using window. location. href

Source: Internet
Author: User

Summary of the inconsistency between paths in IE and FF browsers using window. location. href

I encountered a problem last Friday. I used Firefox when I was working on a project. Last week, I completed the function of a small forum because I did not need to log on to the Forum, user logon is required only when posting and replying. Therefore, an interceptor is added to the system. If you do not log on to the system, the logon page is displayed, after the function is completed, it is no problem to use it in Firefox. IE is rarely used at ordinary times, so I did not test it in IE and put it directly on the server for testing, firefox is still used for testing on the server, and there is no problem, but one of my colleagues encountered a problem when I went to test it. He is using the IE browser, the logon page is displayed when the user does not need to log on. The functions are completely messy and the logon page is always displayed, so the first logon page will not appear at the beginning, then, no matter what button you click, the logon page is displayed.

I started to solve the above problem. At the beginning, I thought it was my interceptor problem, but it was okay when I used Firefox. Then I started the test using IE11, debug the interceptor and then find a problem. When the interceptor first enters, the obtained path is/com/action. action, but when you click the next connection, it becomes/com/action. action. Each time you click a connection, a/com will be added before the method, and/com is my struts2 namespace, however, during the test under FF, the interceptor obtains the/com/action path each time. action, so there is no problem when running in FF.

Then I began to ask du Niang how to solve the problem. The answer that DU Niang gave was that IE was parsing window. location. when href = url, if the url is a relative path, then the IE browser will encounter a problem during parsing and cannot access the url correctly. Because it was in a hurry at the time, I didn't think so much, we will continue to find a solution to this problem online, and then find 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, you can test it locally, whether it is IE, Firefox, or Google. If the problem is solved, you can test it on the server, however, when I got to the server, all the browsers were poor. I clicked on the server and the login page was displayed. I was very depressed. I went on to find the answer on the Internet, however, many of them directly copy the above method, which has no substantial effect at all. Then, they post and ask questions in the blog Park, but they do not get any useful information, maybe they are all in code/code ......., then, I dragged on to the current day and re-read the replies from other people's posts and inquiries. Some people say that the absolute path can be used to solve the problem. Then I changed it with a try and then succeeded.

  The solution is to use the absolute path, so the above url can be changed to "/project name/xxx/xxxAction_xxx.do ",It has been tested that IE, Firefox, and Google on servers and local servers are adaptive. Here we record it and forget it. We hope it can help other people who encounter this problem, if you have any questions, please let us know.

  

Related Article

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.