开发者

Change javascript from src before it is outputted?

Is it possible to change the javascript from <script src="http://example.com/" type="text/javascript"></script> before it is outputted onto the page? The outputted data is in the format document.write('<li><a href="http://example.com/reply/1">UsersName: This is the users message.&开发者_运维知识库lt;/a></li>');

I'd like to change it so the HTML on the page is <li><a href="http://example.com/reply/1">UsersName</a><div id=message">This is the users message.</div></li>


Note: this isn't the best idea, but it's all I can come up with..

In <head>, you could override document.write briefly, manipulate the data, then output it.

E.g.:

(function (write) {
    document.write = function (data) {
        // manipulate data here
        data = data.toLowerCase();

        // output manipulated data
        write(data);

        // set document.write back to normal
        document.write = write;
    };
}(document.write));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜