简体   繁体   中英

including external URL javascript file

I have a main header page that is included in many different applications across a couple of different languages, including Java and classic ASP. The file (file.js) is going to be obsolete soon. We are going to be going to an "out-of-the-box" solution, a new header created by another group. They gave us a link ("google.com") that we need to use to show this new header. I was wondering if there was a simple solution I could implement in my file.js that would show this content to the users. I know an easy way to do it in jsp is
<c:import url="http://google.com"/>

but this won't work in the js file, nor will it work in the jsp. Is there a way for me to do this?

Thank you, Explosive_donut

Obviously the URL you are really given isn't Google. I suppose the second team is able to modify their own (document) headers sent to clients.

First way I think of is to use AJAX to retrieve the contents of the URL and create a div or select an existing to set its new content.

Unfortunately AJAX is restricted to the Same Origin Policy which can be circumvented with CORS (Cross Origin Resource Sharing) . To allow CORS, your remote server as well as your client maschines need to send respective headers. Check out the link for more information.

If you need any more information and/or tutorials, let me know in the comments.

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