在我的 javascript 代码中,我在 iframe 中加载 jsp 页面并传递一些变量,如下所示:
htmlData[i++]="";
然后我必须在执行操作后重新加载该 jsp 页面,我这样做:
accord = ui.newHeader.text();
document.getElementById('mapframe').contentWindow.location.reload();
重新加载有效,只是“accord”变量没有更新。当我从jsp中调用它时,它仍然具有原来的值。重新加载 iframe/jsp 时如何传递新值?
它不应该有任何区别,但我正在使用 jquery,这是针对 Yahoo zimlet 的。
谢谢。
In my javascript code I load a jsp page in an iframe and pass some variables like this:
htmlData[i++]="<iframe id=\"mapframe\" frameborder=\"0\" style=\"width:330px;height:300px\" src=\"" + "mapURL.jsp"
+"&lat=" + AjxStringUtil.urlComponentEncode("33.65")
+"&lng=" + AjxStringUtil.urlComponentEncode("-84.42")
+"&accord=" + AjxStringUtil.urlComponentEncode(accord)
+"\"></iframe>";
Then I have to reload that jsp page after an action, and I do this:
accord = ui.newHeader.text();
document.getElementById('mapframe').contentWindow.location.reload();
The reload works except that the "accord" variable is not getting updated. When I call it from the jsp, it still has its original value. How do I pass the new value when reloading the iframe/jsp?
It shouldn't make any difference, but I am working with jquery and this is for a Yahoo zimlet.
Thanks.
发布评论
评论(1)
“accord”变量如何“更新”?目前,您只是重新加载第一次构建的相同 URL;如果 JavaScript
accord
变量已更改,并且您想要更改 URL 以反映这一情况,则必须构建一个新 URL 并将 iframe 导航到具有不同accord
的新页面范围。注意
contentWindow
历来是 IE 扩展,最好避免使用。此外,如果您必须通过将 HTML 粘合在一起来创建 iframe,则需要先对 URL 进行 HTML 转义,然后再将其包含在标记中。否则,URL 中的&
字符无效,并且当您输入与 HTML 实体名称匹配的参数名称时,可能会导致问题。(我通常更喜欢使用 DOM 方法创建元素,以避免显式 HTML 编码。)
How is the ‘accord’ variable getting ‘updated’? At the moment you are merely reloading the same URL you built the first time round; if the JavaScript
accord
variable has changed and you want to change the URL to reflect that, you must build a new URL and navigate the iframe to the new page with the differentaccord
parameter.Note
contentWindow
is historically an IE extension, and better avoided. Also if you must create your iframe by sticking HTML together, you will need to HTML-escape the URL before including it in the markup. Otherwise the&
characters in the URL are invalid and likely to cause trouble when you hit a parameter name that matches an HTML entity name.(I'd generally prefer to create elements using DOM methods, to avoid having to explicitly HTML-encode.)