Can the src attribute of an iframe perform a POST request?
我需要使用src属性加载iframe。 我需要附加很多附加信息到查询中。 目前,我只是将所有这些信息放在一个像这样的参数中:
1 | <iframe src="mywebsite.com/get_iframe?aVeryLongString"></iframe> |
但是,aVeryLongString可能会很长。 只要我从服务器收到" 414(请求URI太大)"错误。
有没有一种方法可以发出此请求而不会出现此错误?
注意:iframe的网址带有其自己的Content-Security-Policy,因此我不能只使用srcdoc而不是src。 除非有使用srcdoc强制CSP的方法,否则是否可以?
如果
但是,如果由于某种原因您不能这样做(并且可能有多种原因您不能这样做,尤其是
如果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <iframe name="the-iframe"></iframe> (function() { // Scoping IIFE to avoid creating global vars var form, input; form = document.createElement("form"); form.action ="/path/to/the/resource"; // I didn't use your `src` because it's incorrect form.target ="the-iframe"; for (/*...looping through the fields you need to add...*/) { input = document.createElement("input"); input.type ="hidden"; input.name = /*...the field name...*/; input.value = /*...the field value...*/; form.appendChild(input); } document.body.appendChild(form); form.submit(); })(); |
旁注: