R
R
rusgayfer2018-06-06 18:51:48
JavaScript
rusgayfer, 2018-06-06 18:51:48

How to get the value of photo_100 into a function?

You need to get the value data.response[0].photo_100into the function function share_app()for it to work like this

var w = window.open('https://vk.com/share.php?url=https://vk.com/app111111_-{id_cook}&title=Приложение сообщества {group_name}&image=' + data.response[0].photo_100, '', 'scrollbars=1');

var strGET = window.location.search.replace( '?', '');
var params = window
    .location
    .search
    .replace('?','')
    .split('&')
    .reduce(
        function(p,e){
            var a = e.split('=');
            p[ decodeURIComponent(a[0])] = decodeURIComponent(a[1]);
            return p;
        },
        {
    }
    );
  
var verapi = '5.78';
VK.api("groups.getById", {
 "group_ids": params['group_id'], "v": verapi
  }, function (data) {
document.getElementById('group_name').innerHTML = data.response[0].name;
var img = document.getElementById("group_photo"); img.src = data.response[0].photo_100;
var share_photo = data.response[0].photo_100;
});

function share_app() {
  var w = window.open('https://vk.com/share.php?url=https://vk.com/app111_-{id_cook}&title=Приложение сообщества {group_name}&image=' + share_photo , '', 'scrollbars=1');
  w.onload = function() {
  var z = this.document.getElementById("target");
  }
}

Can't get value share_photointo function to work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Nemiro, 2018-06-06
@rusgayfer

Try moving the share_photo declaration outside of the function (from VK.api ):

var verapi = '5.78';
var share_photo;
VK.api("groups.getById", {
 "group_ids": params['group_id'], "v": verapi
  }, function (data) {
document.getElementById('group_name').innerHTML = data.response[0].name;
var img = document.getElementById("group_photo"); img.src = data.response[0].photo_100;
// убираем var
share_photo = data.response[0].photo_100;
});

Or add a parameter to share_app and pass values ​​to it. It will be a more correct option, but the logic will have to be corrected.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question