To force an address bar URL domain change
When connecting via an external link, you may have to change the domain, such as loading it into an i-frame, or loading ajax with jquery.
For example, ajax has a sandbox security, so there is a limitation that prevents pages from being called from other domains.
You can solve this problem by forcibly changing the domain and unifying it.
1. The General Method
The most common use is to declare the path of a document in JavaScript.
However, in the case of ajax, even this may not work.
But it's the easiest and most common way.
<script language=javascript>
document.domain = "www.A.com";
</script>
If you do this, even if it is A.com without www, it recognizes it as www.A.com and calls the page.
However, you must read the four precautions at the bottom to avoid failure.
2. How to match domains
When the expected address path is obvious, it is more certain to do it as follows.
<script language=javascript>
var url1 = 'www.A.com';
var url2 = 'A.com';
if( document.URL.match(url1) ) document.location.href = document.URL.replace(url1, url2);
</script>
If a visitor wants to access A.com, but he or she wants to access www.A.com, this will force him or her to start with A.com
For example, www.A.com/search?If query=test appears in the URL, force A.com/search?It changes to query=test.
Enter the desired domain address for url1 and url2.
In the if part, make url2 by unifying url1 and url2.
url1 is the problematic path address and url2 is the desired path address.
Even if there are various problematic routes such as blog and img as well as www, you can continue to increase it to url3 and url4 above.
3. Other Advice
There's JSON and so on.
JSON has a long content, so I'll mention it next time.
4. Precautions
However, if you use the first method, document.domain = "Address"; there is a point to note.
Some pages may be useful, but the domain paths within the site are intertwined, which can cause many problems, such as not being saved on other pages.
Therefore, if document.domain is applied on one page, it is inevitable to apply it on all pages.
In addition, in the case of an eye frame, it is not necessary to apply it only to the parent page, but also to declare document.domain in the document within the called eye frame.
However, if you use document.URL.match, the second method, you can only declare and use it in the parent window.
[Forced to change the URL domain]
'Knowledge (Ver English)' 카테고리의 다른 글
The page where I shouldn't add sense? (0) | 2022.11.11 |
---|---|
How to show, hide using display - CSS (0) | 2022.11.10 |
Korea needs a minimum wage and living wage system (0) | 2022.11.08 |
Where the Night Is - Lee Mun-se (0) | 2022.11.07 |
Georgia on my mine - Ray Charles (0) | 2022.11.06 |