Can JavaScript access source code of a [removed] element?

前端 未结 2 1901
你的背包
你的背包 2020-12-06 12:24


Can

2条回答
  •  囚心锁ツ
    2020-12-06 12:37

    No, this would allow to retrieve the contents of any URL, which would break some security policies. (This would be an equivalent of an ajax get request without same-domain checks.)

    However, since foo.js is on the same domain than the page you can fetch it with an ajax request. Example with jQuery:

    $.get('foo.js', function(source_code) {
        alert('foo.js contains ' + source_code);
    });
    

提交回复
热议问题