J
J
Jony13372016-04-19 20:25:33
JavaScript
Jony1337, 2016-04-19 20:25:33

How to make a redirect if the code action was followed in javascript?

Hello everyone
, this code example checks if a person has published or not a post in the Odnoklassniki social network,
if he has published, then returns alert if not, then returns nothing
How to set it to return redirect to another address if he shared and alert if he did not share?
Here is the code

<div id="ok_shareWidget"></div>
        <script>
          !function (d, id, did, st) {
            var js = d.createElement("script");
            js.src = "<? echo $klass22; ?>";
            js.onload = js.onreadystatechange = function () {
            if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") {
            if (!this.executed) {
              this.executed = true;
              setTimeout(function () {
              OK.CONNECT.insertShareWidget(id,did,st);
              }, 0);
            }
            }};
            d.documentElement.appendChild(js);
          }(document,"ok_shareWidget","http://site.ru/t/load.php?id=<? echo $create_id;?>","{width:125,height:50,st:'straight',sz:45,ck:1,nc:1}");
          
          function listenForShare() {
            if (window.addEventListener) {
              window.addEventListener('message', onShare, false);
            } else {
              window.attachEvent('onmessage', onShare);
            }
          }
          function onShare(e) {
            var args = e.data.split("$");
            if (args[0] == "ok_shared") {
              alert(args[1]); // Вывод идентификатора фрейма кнопки - в случае нескольких кнопок на одной странице, по нему можно определить какая именно была кликнута
              if (alert)
              $( '#baner_grup' ).show();
              
              $( '.classs' ).html('<meta http-equiv="refresh" content="0; url=http://example.ru/hh.php" />');
              
              $( '#class' ).hide();
              $( '.player' ).hide();
              
              
            }
          }
          listenForShare();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-04-20
@Jony1337

so use location.href = " yoururl.con "; Or what do you mean by redirect ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question