0
我正在构建一个填充了iFrame内容的模式。在那个模式里我有一个Dropbox上传功能。我试图做的是当有人成功上传图片并点击“关闭”按钮,信息被发回到原始网站。然后我可以显示一个带有“图片上传”或其他东西的好按钮。 问题是,我不断收到一个错误说SyntaxError: An invalid or illegal string was specified..... window.parent.postMessage('close', url);
iFrame不回发postMessage
Iframe所网址:
http://www.webshop.com/dropboxupload/?id=1042013-72374&url=http://www.website.com/&place=0#
代码:
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value){vars[key] = value; });
return vars;
}
function close_parent(){
var url = getUrlVars()["url"];
//console.log(url);
window.parent.postMessage('close', url);
}
当我在代码中使用的console.log我得到的只是“htt”没有其他的网址。
的HTML关闭按钮:
<a class="close uploadbutton" onclick="javascript:close_parent();" href="#">Voltooien</a>
返回到原来的站点时,该代码:
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
var url = window.location.href;
eventer(messageEvent,function(e) {
if(e.data == 'close'){
up_popover_hide();
var urlIframe = $('iframe#upload').attr("src");
var indexPlace = getUrlVars(urlIframe)["place"];
var idUpload = getUrlVars(urlIframe)["id"];
$('.placeholder.index_'+indexPlace+' .upload_'+idUpload).html('File uploaded!');
}else{}},false);
我实在看不出有什么我做错了,做不理解为什么我只是得到“htt”而不是完整的url。
任何帮助非常感谢!
http://danheberden.com/share/feec82.png –
@丹Heberden:好的thx为您的答案。那么怎么了?我不明白为什么这不应该工作!有什么建议么? – Meules