How to use JavaScript to access cross domain iFrame content?

后端 未结 6 1304
时光说笑
时光说笑 2021-01-28 16:20

I would like to use this code

window.parent.document.getElementById(\'message\').value  += \"\\r\\n\\r\\n[img]\"+response+\"[/img]\";

It works

6条回答
  •  失恋的感觉
    2021-01-28 17:00

    You can if your browser have disabled security, for chrome it's

    "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security
    

    Update: I'm surprised that people keep devoting it because they consider it harmful, so here I add some additional details for peoples who don't know basics of web security and still try to develop for it.

    DON'T use this solution if

    • you are using chrome plugins or apps which are not trusted by you, or

    • you have opened other sites in the chrome, or

    • you have some malicious chrome processes

    • your site is using any external resources.

    To make this solution completely safe, configure your firewall to block all connections except one to which you are making CORS connection.

    Also, don't use this solution if your connection endpoint isn't trusted.

提交回复
热议问题