开发者

Change javascript from src before it is outputted?

开发者 https://www.devze.com 2023-02-02 01:15 出处:网络
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 forma

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

精彩评论

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