English 中文(简体)
如何在不执行《 the》或《圣经》的情况下装载?
原标题:What are the ways to load JavaScript or CSS without executing them?

I m了解通过添加<条码>和带的有活力的文字/剪辑;风格和“;或<link>贴在网页上或厅,但一旦下载,将由浏览器执行。 我正在考虑其他下载方式,但没有执行javascript/cs代码。 首先,我想到的是XMLHttpRequest:

//simple execution received script
var executeScript = function(code){
    eval(code);
};
//create XMLHttpRequest in cross-browser manner
var xhr = createXMLHTTPObject();
//check whether file is loaded
var checkStatus = function(){
    if(xhr.readyState  == 4){
        if(xhr.status >= 200 && xhr.status < 300 || xhr == 304){
            executeScript(xhr.responseText);   
        }
        else {//error
        }
    }
};
//do request
xhr.open( get , http://podlipensky.com/examples/dynamicscript/hey.js , true);
xhr.onreadystatechange = checkStatus;
xhr.send(null);

但是,在这种情况下,由于Same Origin政策,我们只用同一领域的文字加以限制(不过我们可以尝试用.CORS)。

另一种做法是,在网页上添加动态的<条码>iframe,然后在<条码>上添加<条码>>>>>> 符号<>>>>,这样,文字在下载后即予以执行,但在另一页(<条码>>iframe上。

Are there any other ways to download and not execute the script?

UPDATE:

下载但不执行javascript/cs是有用的原因之一,是先上载第三方图书馆,但只需要使用这些图书馆。

最佳回答

You can also use an iframe and use the script/css URL as the src of the frame (so it isn t evaluated/applied at all), although you d want to be sure in that case that the JavaScript/CSS was delivered with Content-Type text/plain to avoid unfortunate things happening with < characters and such. Although you should run into SOP issues with this approach as well, on a decent browser, if the iframe src is from a different origin.

除此以外,我认为你基本上可以选择你们的名单。

问题回答

仅举出另外一种选择,即使用<代码><object> tag:

<object data="http://podlipensky.com/examples/dynamicscript/hey.js" />

http://www.phpied.com/preload-csjavascript- Without-execution/“rel=”nofollow” 。 因此,我只与大家分享我的调查结果,希望这样做将是有益的。

If your script simplty defines a function then it can be executed without actually running anything. Of course, this would require collaboration from both sides ala JSONP

//jsonp
var result = {/*...*/};

//missingnonp
var f = function(){ /**/ };

假设你控制提供该网页的服务器,你想把有关联合材料装上该页面,最容易的方法是将欧洲复兴开发银行的URL送给你的服务器,从该服务器上装载(例如,通过PHP文档——目标——产出(收益)))并由于亚洲复兴开发银行的号召而收回。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签