简体   繁体   中英

How to link external website to internal javascript page

I have a website lets call it example.com , it is hosted at an external hosting provider. On the site I have a page http://example.com/msg.php that needs to reference a JavaScript from an intranet site lets say running on example_intranet.com, so I have a script reference like..

 <script src="http://example_intranet.com/js/messaging.js" type="text/javascipt">

I'm aware of cross-domain security issues and have setup the necessary CORS on the example.com site and pages.

When you visit http://example.com/msg.php from OUTSIDE the company network (example_intranet.com) everything works as expected, but when you visit the same page from within (INSIDE) the network the page doesn't appear to resolve the javascript include ..

any suggestions on how to fix this?That is to be able to have the reference javascirpt work from inside the network.

I'm guessing this is a DNS issue, not about code. The intranet URL domain likely resolves to a different "internal" IP address when you are on the company network, and when you are outside it resolves to a public IP address.

Theoretical scenario:

When you are in the company network, the intranet URL gets resolved to a local IP, like 192.xxx or 10.xxx SO when you visit your page on the external host your machine is trying to find the javascript file using that internal IP, but it might be looking for it inside the network of the external host, and won't find it.

As an experiment, try changing the path to your javascript file to use the public IP of that intranet URL instead of the domain name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM