如何从javascript代码获取执行结果链接

时间:2013-09-13 04:49:44

标签: javascript php

我正在使用鸟舍照片编辑器,当有人完成编辑并点击保存时,我想在执行onsave功能时获取已保存图像的链接,并希望在输入字段中获取新生成的图像链接:

<html>
<body onSave="autofill();">
<input type="text" name="name_textbox" id="id_textbox" />   
<script type="text/javascript" language="JavaScript">
function autofill(){
    var object = document.getElementsByName('name_textbox');
    object.item(0).value="Autofill successful.";    
}</script>
</body>
</html>

这里是鸟舍照片编辑器代码onsave功能代码:

<script type='text/javascript'>var featherEditor = new Aviary.Feather({
   apiKey: 'ceegvx4siylhayrr',
   apiVersion: 3,
   theme: 'dark', // Check out our new 'light' and 'dark' themes!
   tools: 'all',
   appendTo: '',
   onSave: function(imageID, newURL) {
       var img = document.getElementById(imageID);
       img.src = newURL;
   },
   onError: function(errorObj) {
       alert(errorObj.message);
   }
});
function launchEditor(id, src) {
   featherEditor.launch({
       image: id,
       url: src
   });
  return false;
}
</script>

<div id='injection_site'></div>
<img id='image1' src='http://images.aviary.com/imagesv5/feather_default.jpg'/>
<!-- Add an edit button, passing the HTML id of the image and the public URL of the image->
<p><input type='image' src='http://images.aviary.com/images/edit-photo.png' value='Edit    photo' onclick="return launchEditor('image1', 'http://images.aviary.com/imagesv5/feather_default.jpg');" /></p>

1 个答案:

答案 0 :(得分:0)

如果您想要将新图片网址添加到输入字段的值,请执行以下操作:

..
onSave: function(imageID, newURL) {
   var img = document.getElementById(imageID);
   img.src = newURL;
   document.getElementById('your_input_field_id').value = newURL;
}

或者如果您想更改图像来源:

..
onSave: function(imageID, newURL) {
   var img = document.getElementById(imageID);
   img.src = newURL;
   document.getElementById('image1').src = newURL;
}