简体   繁体   中英

Is possible to read script tag src URL content using JavaScript/jQuery

Please guide me. Is possible to read script tag src URL content using JavaScript/jQuery. Please don't suggest JSON/Ajax/iframe options.

I have tried like

<script src="http://www.test.com" id="test">

document.getElementById('test').src

but it give only src URL.

My Exact requirements is, I have two application, each in different web server with www.siteA.com and www.siteB.com.

In Server2, I have cross origin and iframe restriction to access the application. Example: If a request is coming from server1(siteA) to server2(siteB) via Ajax or iframe, it's restricted to access the siteB page content. But If I load siteB in script tag it's loaded, but I'm not able to get the content.

So I mentioned above, don't suggest iframe and Ajax. Help me to achieve this.

The best way really is AJAX, but it does sound like CORS is an issue for you. The only other option I can think of would be to open the page in a new browser window, although I don't know what kind of user experience implications that will have on your application.

You can open a new browser window by:

function showContent(){
    var url = document.getElementById("test").src;
    window.open(url, "_blank");
}

Although if you take this route, you shouldn't put the url on a script tag, because the browser will download it once (via the script tag), and then a second time on the window.open.

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