js新标签打开页面

JavaScript018

js新标签打开页面,第1张

这个东西要通过后端实现websocket类似的协议,再通过js的websocket接口来实现。

否则用比较笨的方法,打开新的页面时候建立一个计时器(setInterval),反复通过ajax轮询一个接口,接口得到某个值,ajax(fetch或者XMLRequest)取得这个值,然后把这个值插入到该插入的地方。最后清除计时器(clearInterval)

这里类似于友情链接

js代码:

<script type='text/JavaScript'> function MM_jumpMenu(selObj,restore){ if (selObj.options[selObj.selectedIndex].value!='xx') { eval(window.open(selObj.options[selObj.selectedIndex].value)) if (restore) selObj.selectedIndex=0 } }</script>

html代码:

<form name='form_link' id='form_link'> <select name='menu_link' onchange='MM_jumpMenu(this,0)'> <option value='xx'>---友情连接---</option>

<option value='链接地址' style='color:#'>链接名称</option>

</select>

</form>

通过执行js

from selenium import webdriver 

import time

# 方式1:通过执行js打开新的标签页driver = webdriver.Chrome()

driver.get("http://login.taobao.com")

js ="window.open('http://www.sogou.com')"driver.execute_script(js)

time.sleep(5)

driver.quit()

关闭标签页

driver.close()