如果Variable等于False,则通过JavaScript重定向?

时间:2017-07-06 22:18:53

标签: javascript

我已经尝试过我所知道的所有事情(不是很多),所以这里的代码没有尝试重定向:

import requests
url = 'http://praktoreio.pamestoixima.gr/web/services/rs/
iFlexBetting/retail/games/15104/0.json?
shortTourn=true&startDrawNumber=686&endDrawNumber=686&sportId=s-
441&marketIds=0&marketIds=0A&marketIds=1&marketIds=69&marketIds=68&marketIds
=20&marketIds=21&marketIds=8&locale=en&brandId=defaultBrand&channelId=0'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'}
resp = requests.get(url, headers=headers)
html = resp.json()
data_1 = html[0]['markets'][0]['codes'][0]['oddPerSet']['1']
data_X = html[0]['markets'][0]['codes'][1]['oddPerSet']['1']
data_2 = html[0]['markets'][0]['codes'][2]['oddPerSet']['1']
print('odds for win:', data_1)
print('odds for draw:', data_X)
print('odds for lose:', data_2)
data_CODE_0 = html[0]['code']
print('Game code:', data_CODE_0)

请帮帮我:((

1 个答案:

答案 0 :(得分:0)

if (!blacklisted){
  window.location = "URL goes here";
}

这与黑名单相反。如果黑名单为假,则条件为真,重定向发生。

编辑:navigator.geolocation是异步的,因此您需要处理回调中的所有逻辑

function displayPosition(pos) {
  var mylat = pos.coords.latitude;
  var mylong = pos.coords.longitude;
  var thediv = document.getElementById('locationinfo');
  thediv.innerHTML = '<p>Your longitude is :' + mylong + ' and your latitide is ' + mylat + '</p>';

  var blacklisted = false;
  for (let x of Object.values(blacklisted_areas)) {
    if (mylat === x[0] && mylong === x[1]) {
      blacklisted = true;
    }
  }
  if(!blacklisted){
    window.location="insertURLHere";
  }
}

如果有效,请告诉我