www.91084.com

GVKun编程网logo

使用JavaScript更改重新加载时当前页面的URL(js实现页面重新加载)

13

针对使用JavaScript更改重新加载时当前页面的URL和js实现页面重新加载这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展535种使用JavaScript重新加载页面的方法、javas

针对使用JavaScript更改重新加载时当前页面的URLjs实现页面重新加载这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展535种使用JavaScript重新加载页面的方法、javascript - 第二次ajax提取页面的时候,main.js没有重新加载,或者说,所有的js都没有重新加载的问题、javascript – 使用jQuery在页面加载时将字符串添加到url?、javascript – 使用jQuery重新加载特定元素等相关知识,希望可以帮助到你。

本文目录一览:

使用JavaScript更改重新加载时当前页面的URL(js实现页面重新加载)

使用JavaScript更改重新加载时当前页面的URL(js实现页面重新加载)

我的要求是在单击刷新图标或Ctrl R时更改当前页面的URL.即在刷新时,重新加载另一个页面(不同的URL).并且它应该支持所有浏览器.我已经尝试了以下代码段.但是它不起作用.

window.onbeforeunload = function(e) {
  window.location.href = 'www.google.com';
};

“ google.com”应为刷新当前页面时我页面的URL.但这与window.onbeforeunload()无关.

解决方法:

OnBeforeUnload需要一个返回值才能工作,但实际上,它只会显示一条消息,询问用户是否确定要离开该页面(就像Facebook在您尝试保留一些待处理的更改而离开页面时一样).

据我所知,Web浏览器不想让您对此进行控制,这主要是由于网站在用户尝试离开时会重定向用户并进行此类操作,因此,没有什么比“标准方法”更重要的了,即使您找到了解决方法,我很确定它不会在所有浏览器上都起作用.
但是,为什么客户希望他的网站上有这种行为?至少在我看来,他将获得的唯一一件事是给最终用户带来可怕的用户体验.

535种使用JavaScript重新加载页面的方法

535种使用JavaScript重新加载页面的方法

除了location = location之外还有534中方法重新加载页面

  1. location = location
  2. location = location.href
  3. location = window.location
  4. location = self.location
  5. location = window.location.href
  6. location = self.location.href
  7. location = location[''href'']
  8. location = window[''location'']
  9. location = window[''location''].href
  10. location = window[''location''][''href'']
  11. location = window.location[''href'']
  12. location = self[''location'']
  13. location = self[''location''].href
  14. location = self[''location''][''href'']
  15. location = self.location[''href'']
  16. location.assign(location)
  17. location.replace(location)
  18. window.location.assign(location)
  19. window.location.replace(location)
  20. self.location.assign(location)
  21. self.location.replace(location)
  22. location[''assign''](location)
  23. location[''replace''](location)
  24. window.location[''assign''](location)
  25. window.location[''replace''](location)
  26. window[''location''].assign(location)
  27. window[''location''].replace(location)
  28. window[''location''][''assign''](location)
  29. window[''location''][''replace''](location)
  30. self.location[''assign''](location)
  31. self.location[''replace''](location)
  32. self[''location''].assign(location)
  33. self[''location''].replace(location)
  34. self[''location''][''assign''](location)
  35. self[''location''][''replace''](location)
  36. location.href = location
  37. location.href = location.href
  38. location.href = window.location
  39. location.href = self.location
  40. location.href = window.location.href
  41. location.href = self.location.href
  42. location.href = location[''href'']
  43. location.href = window[''location'']
  44. location.href = window[''location''].href
  45. location.href = window[''location''][''href'']
  46. location.href = window.location[''href'']
  47. location.href = self[''location'']
  48. location.href = self[''location''].href
  49. location.href = self[''location''][''href'']
  50. location.href = self.location[''href'']
  51. location.assign(location.href)
  52. location.replace(location.href)
  53. window.location.assign(location.href)
  54. window.location.replace(location.href)
  55. self.location.assign(location.href)
  56. self.location.replace(location.href)
  57. location[''assign''](location.href)
  58. location[''replace''](location.href)
  59. window.location[''assign''](location.href)
  60. window.location[''replace''](location.href)
  61. window[''location''].assign(location.href)
  62. window[''location''].replace(location.href)
  63. window[''location''][''assign''](location.href)
  64. window[''location''][''replace''](location.href)
  65. self.location[''assign''](location.href)
  66. self.location[''replace''](location.href)
  67. self[''location''].assign(location.href)
  68. self[''location''].replace(location.href)
  69. self[''location''][''assign''](location.href)
  70. self[''location''][''replace''](location.href)
  71. window.location = location
  72. window.location = location.href
  73. window.location = window.location
  74. window.location = self.location
  75. window.location = window.location.href
  76. window.location = self.location.href
  77. window.location = location[''href'']
  78. window.location = window[''location'']
  79. window.location = window[''location''].href
  80. window.location = window[''location''][''href'']
  81. window.location = window.location[''href'']
  82. window.location = self[''location'']
  83. window.location = self[''location''].href
  84. window.location = self[''location''][''href'']
  85. window.location = self.location[''href'']
  86. location.assign(window.location)
  87. location.replace(window.location)
  88. window.location.assign(window.location)
  89. window.location.replace(window.location)
  90. self.location.assign(window.location)
  91. self.location.replace(window.location)
  92. location[''assign''](window.location)
  93. location[''replace''](window.location)
  94. window.location[''assign''](window.location)
  95. window.location[''replace''](window.location)
  96. window[''location''].assign(window.location)
  97. window[''location''].replace(window.location)
  98. window[''location''][''assign''](window.location)
  99. window[''location''][''replace''](window.location)
  100. self.location[''assign''](window.location)
  101. self.location[''replace''](window.location)
  102. self[''location''].assign(window.location)
  103. self[''location''].replace(window.location)
  104. self[''location''][''assign''](window.location)
  105. self[''location''][''replace''](window.location)
  106. self.location = location
  107. self.location = location.href
  108. self.location = window.location
  109. self.location = self.location
  110. self.location = window.location.href
  111. self.location = self.location.href
  112. self.location = location[''href'']
  113. self.location = window[''location'']
  114. self.location = window[''location''].href
  115. self.location = window[''location''][''href'']
  116. self.location = window.location[''href'']
  117. self.location = self[''location'']
  118. self.location = self[''location''].href
  119. self.location = self[''location''][''href'']
  120. self.location = self.location[''href'']
  121. location.assign(self.location)
  122. location.replace(self.location)
  123. window.location.assign(self.location)
  124. window.location.replace(self.location)
  125. self.location.assign(self.location)
  126. self.location.replace(self.location)
  127. location[''assign''](self.location)
  128. location[''replace''](self.location)
  129. window.location[''assign''](self.location)
  130. window.location[''replace''](self.location)
  131. window[''location''].assign(self.location)
  132. window[''location''].replace(self.location)
  133. window[''location''][''assign''](self.location)
  134. window[''location''][''replace''](self.location)
  135. self.location[''assign''](self.location)
  136. self.location[''replace''](self.location)
  137. self[''location''].assign(self.location)
  138. self[''location''].replace(self.location)
  139. self[''location''][''assign''](self.location)
  140. self[''location''][''replace''](self.location)
  141. window.location.href = location
  142. window.location.href = location.href
  143. window.location.href = window.location
  144. window.location.href = self.location
  145. window.location.href = window.location.href
  146. window.location.href = self.location.href
  147. window.location.href = location[''href'']
  148. window.location.href = window[''location'']
  149. window.location.href = window[''location''].href
  150. window.location.href = window[''location''][''href'']
  151. window.location.href = window.location[''href'']
  152. window.location.href = self[''location'']
  153. window.location.href = self[''location''].href
  154. window.location.href = self[''location''][''href'']
  155. window.location.href = self.location[''href'']
  156. location.assign(window.location.href)
  157. location.replace(window.location.href)
  158. window.location.assign(window.location.href)
  159. window.location.replace(window.location.href)
  160. self.location.assign(window.location.href)
  161. self.location.replace(window.location.href)
  162. location[''assign''](window.location.href)
  163. location[''replace''](window.location.href)
  164. window.location[''assign''](window.location.href)
  165. window.location[''replace''](window.location.href)
  166. window[''location''].assign(window.location.href)
  167. window[''location''].replace(window.location.href)
  168. window[''location''][''assign''](window.location.href)
  169. window[''location''][''replace''](window.location.href)
  170. self.location[''assign''](window.location.href)
  171. self.location[''replace''](window.location.href)
  172. self[''location''].assign(window.location.href)
  173. self[''location''].replace(window.location.href)
  174. self[''location''][''assign''](window.location.href)
  175. self[''location''][''replace''](window.location.href)
  176. self.location.href = location
  177. self.location.href = location.href
  178. self.location.href = window.location
  179. self.location.href = self.location
  180. self.location.href = window.location.href
  181. self.location.href = self.location.href
  182. self.location.href = location[''href'']
  183. self.location.href = window[''location'']
  184. self.location.href = window[''location''].href
  185. self.location.href = window[''location''][''href'']
  186. self.location.href = window.location[''href'']
  187. self.location.href = self[''location'']
  188. self.location.href = self[''location''].href
  189. self.location.href = self[''location''][''href'']
  190. self.location.href = self.location[''href'']
  191. location.assign(self.location.href)
  192. location.replace(self.location.href)
  193. window.location.assign(self.location.href)
  194. window.location.replace(self.location.href)
  195. self.location.assign(self.location.href)
  196. self.location.replace(self.location.href)
  197. location[''assign''](self.location.href)
  198. location[''replace''](self.location.href)
  199. window.location[''assign''](self.location.href)
  200. window.location[''replace''](self.location.href)
  201. window[''location''].assign(self.location.href)
  202. window[''location''].replace(self.location.href)
  203. window[''location''][''assign''](self.location.href)
  204. window[''location''][''replace''](self.location.href)
  205. self.location[''assign''](self.location.href)
  206. self.location[''replace''](self.location.href)
  207. self[''location''].assign(self.location.href)
  208. self[''location''].replace(self.location.href)
  209. self[''location''][''assign''](self.location.href)
  210. self[''location''][''replace''](self.location.href)
  211. location[''href''] = location
  212. location[''href''] = location.href
  213. location[''href''] = window.location
  214. location[''href''] = self.location
  215. location[''href''] = window.location.href
  216. location[''href''] = self.location.href
  217. location[''href''] = location[''href'']
  218. location[''href''] = window[''location'']
  219. location[''href''] = window[''location''].href
  220. location[''href''] = window[''location''][''href'']
  221. location[''href''] = window.location[''href'']
  222. location[''href''] = self[''location'']
  223. location[''href''] = self[''location''].href
  224. location[''href''] = self[''location''][''href'']
  225. location[''href''] = self.location[''href'']
  226. location.assign(location[''href''])
  227. location.replace(location[''href''])
  228. window.location.assign(location[''href''])
  229. window.location.replace(location[''href''])
  230. self.location.assign(location[''href''])
  231. self.location.replace(location[''href''])
  232. location[''assign''](location[''href''])
  233. location[''replace''](location[''href''])
  234. window.location[''assign''](location[''href''])
  235. window.location[''replace''](location[''href''])
  236. window[''location''].assign(location[''href''])
  237. window[''location''].replace(location[''href''])
  238. window[''location''][''assign''](location[''href''])
  239. window[''location''][''replace''](location[''href''])
  240. self.location[''assign''](location[''href''])
  241. self.location[''replace''](location[''href''])
  242. self[''location''].assign(location[''href''])
  243. self[''location''].replace(location[''href''])
  244. self[''location''][''assign''](location[''href''])
  245. self[''location''][''replace''](location[''href''])
  246. window[''location''] = location
  247. window[''location''] = location.href
  248. window[''location''] = window.location
  249. window[''location''] = self.location
  250. window[''location''] = window.location.href
  251. window[''location''] = self.location.href
  252. window[''location''] = location[''href'']
  253. window[''location''] = window[''location'']
  254. window[''location''] = window[''location''].href
  255. window[''location''] = window[''location''][''href'']
  256. window[''location''] = window.location[''href'']
  257. window[''location''] = self[''location'']
  258. window[''location''] = self[''location''].href
  259. window[''location''] = self[''location''][''href'']
  260. window[''location''] = self.location[''href'']
  261. location.assign(window[''location''])
  262. location.replace(window[''location''])
  263. window.location.assign(window[''location''])
  264. window.location.replace(window[''location''])
  265. self.location.assign(window[''location''])
  266. self.location.replace(window[''location''])
  267. location[''assign''](window[''location''])
  268. location[''replace''](window[''location''])
  269. window.location[''assign''](window[''location''])
  270. window.location[''replace''](window[''location''])
  271. window[''location''].assign(window[''location''])
  272. window[''location''].replace(window[''location''])
  273. window[''location''][''assign''](window[''location''])
  274. window[''location''][''replace''](window[''location''])
  275. self.location[''assign''](window[''location''])
  276. self.location[''replace''](window[''location''])
  277. self[''location''].assign(window[''location''])
  278. self[''location''].replace(window[''location''])
  279. self[''location''][''assign''](window[''location''])
  280. self[''location''][''replace''](window[''location''])
  281. window[''location''].href = location
  282. window[''location''].href = location.href
  283. window[''location''].href = window.location
  284. window[''location''].href = self.location
  285. window[''location''].href = window.location.href
  286. window[''location''].href = self.location.href
  287. window[''location''].href = location[''href'']
  288. window[''location''].href = window[''location'']
  289. window[''location''].href = window[''location''].href
  290. window[''location''].href = window[''location''][''href'']
  291. window[''location''].href = window.location[''href'']
  292. window[''location''].href = self[''location'']
  293. window[''location''].href = self[''location''].href
  294. window[''location''].href = self[''location''][''href'']
  295. window[''location''].href = self.location[''href'']
  296. location.assign(window[''location''].href)
  297. location.replace(window[''location''].href)
  298. window.location.assign(window[''location''].href)
  299. window.location.replace(window[''location''].href)
  300. self.location.assign(window[''location''].href)
  301. self.location.replace(window[''location''].href)
  302. location[''assign''](window[''location''].href)
  303. location[''replace''](window[''location''].href)
  304. window.location[''assign''](window[''location''].href)
  305. window.location[''replace''](window[''location''].href)
  306. window[''location''].assign(window[''location''].href)
  307. window[''location''].replace(window[''location''].href)
  308. window[''location''][''assign''](window[''location''].href)
  309. window[''location''][''replace''](window[''location''].href)
  310. self.location[''assign''](window[''location''].href)
  311. self.location[''replace''](window[''location''].href)
  312. self[''location''].assign(window[''location''].href)
  313. self[''location''].replace(window[''location''].href)
  314. self[''location''][''assign''](window[''location''].href)
  315. self[''location''][''replace''](window[''location''].href)
  316. window[''location''][''href''] = location
  317. window[''location''][''href''] = location.href
  318. window[''location''][''href''] = window.location
  319. window[''location''][''href''] = self.location
  320. window[''location''][''href''] = window.location.href
  321. window[''location''][''href''] = self.location.href
  322. window[''location''][''href''] = location[''href'']
  323. window[''location''][''href''] = window[''location'']
  324. window[''location''][''href''] = window[''location''].href
  325. window[''location''][''href''] = window[''location''][''href'']
  326. window[''location''][''href''] = window.location[''href'']
  327. window[''location''][''href''] = self[''location'']
  328. window[''location''][''href''] = self[''location''].href
  329. window[''location''][''href''] = self[''location''][''href'']
  330. window[''location''][''href''] = self.location[''href'']
  331. location.assign(window[''location''][''href''])
  332. location.replace(window[''location''][''href''])
  333. window.location.assign(window[''location''][''href''])
  334. window.location.replace(window[''location''][''href''])
  335. self.location.assign(window[''location''][''href''])
  336. self.location.replace(window[''location''][''href''])
  337. location[''assign''](window[''location''][''href''])
  338. location[''replace''](window[''location''][''href''])
  339. window.location[''assign''](window[''location''][''href''])
  340. window.location[''replace''](window[''location''][''href''])
  341. window[''location''].assign(window[''location''][''href''])
  342. window[''location''].replace(window[''location''][''href''])
  343. window[''location''][''assign''](window[''location''][''href''])
  344. window[''location''][''replace''](window[''location''][''href''])
  345. self.location[''assign''](window[''location''][''href''])
  346. self.location[''replace''](window[''location''][''href''])
  347. self[''location''].assign(window[''location''][''href''])
  348. self[''location''].replace(window[''location''][''href''])
  349. self[''location''][''assign''](window[''location''][''href''])
  350. self[''location''][''replace''](window[''location''][''href''])
  351. window.location[''href''] = location
  352. window.location[''href''] = location.href
  353. window.location[''href''] = window.location
  354. window.location[''href''] = self.location
  355. window.location[''href''] = window.location.href
  356. window.location[''href''] = self.location.href
  357. window.location[''href''] = location[''href'']
  358. window.location[''href''] = window[''location'']
  359. window.location[''href''] = window[''location''].href
  360. window.location[''href''] = window[''location''][''href'']
  361. window.location[''href''] = window.location[''href'']
  362. window.location[''href''] = self[''location'']
  363. window.location[''href''] = self[''location''].href
  364. window.location[''href''] = self[''location''][''href'']
  365. window.location[''href''] = self.location[''href'']
  366. location.assign(window.location[''href''])
  367. location.replace(window.location[''href''])
  368. window.location.assign(window.location[''href''])
  369. window.location.replace(window.location[''href''])
  370. self.location.assign(window.location[''href''])
  371. self.location.replace(window.location[''href''])
  372. location[''assign''](window.location[''href''])
  373. location[''replace''](window.location[''href''])
  374. window.location[''assign''](window.location[''href''])
  375. window.location[''replace''](window.location[''href''])
  376. window[''location''].assign(window.location[''href''])
  377. window[''location''].replace(window.location[''href''])
  378. window[''location''][''assign''](window.location[''href''])
  379. window[''location''][''replace''](window.location[''href''])
  380. self.location[''assign''](window.location[''href''])
  381. self.location[''replace''](window.location[''href''])
  382. self[''location''].assign(window.location[''href''])
  383. self[''location''].replace(window.location[''href''])
  384. self[''location''][''assign''](window.location[''href''])
  385. self[''location''][''replace''](window.location[''href''])
  386. self[''location''] = location
  387. self[''location''] = location.href
  388. self[''location''] = window.location
  389. self[''location''] = self.location
  390. self[''location''] = window.location.href
  391. self[''location''] = self.location.href
  392. self[''location''] = location[''href'']
  393. self[''location''] = window[''location'']
  394. self[''location''] = window[''location''].href
  395. self[''location''] = window[''location''][''href'']
  396. self[''location''] = window.location[''href'']
  397. self[''location''] = self[''location'']
  398. self[''location''] = self[''location''].href
  399. self[''location''] = self[''location''][''href'']
  400. self[''location''] = self.location[''href'']
  401. location.assign(self[''location''])
  402. location.replace(self[''location''])
  403. window.location.assign(self[''location''])
  404. window.location.replace(self[''location''])
  405. self.location.assign(self[''location''])
  406. self.location.replace(self[''location''])
  407. location[''assign''](self[''location''])
  408. location[''replace''](self[''location''])
  409. window.location[''assign''](self[''location''])
  410. window.location[''replace''](self[''location''])
  411. window[''location''].assign(self[''location''])
  412. window[''location''].replace(self[''location''])
  413. window[''location''][''assign''](self[''location''])
  414. window[''location''][''replace''](self[''location''])
  415. self.location[''assign''](self[''location''])
  416. self.location[''replace''](self[''location''])
  417. self[''location''].assign(self[''location''])
  418. self[''location''].replace(self[''location''])
  419. self[''location''][''assign''](self[''location''])
  420. self[''location''][''replace''](self[''location''])
  421. self[''location''].href = location
  422. self[''location''].href = location.href
  423. self[''location''].href = window.location
  424. self[''location''].href = self.location
  425. self[''location''].href = window.location.href
  426. self[''location''].href = self.location.href
  427. self[''location''].href = location[''href'']
  428. self[''location''].href = window[''location'']
  429. self[''location''].href = window[''location''].href
  430. self[''location''].href = window[''location''][''href'']
  431. self[''location''].href = window.location[''href'']
  432. self[''location''].href = self[''location'']
  433. self[''location''].href = self[''location''].href
  434. self[''location''].href = self[''location''][''href'']
  435. self[''location''].href = self.location[''href'']
  436. location.assign(self[''location''].href)
  437. location.replace(self[''location''].href)
  438. window.location.assign(self[''location''].href)
  439. window.location.replace(self[''location''].href)
  440. self.location.assign(self[''location''].href)
  441. self.location.replace(self[''location''].href)
  442. location[''assign''](self[''location''].href)
  443. location[''replace''](self[''location''].href)
  444. window.location[''assign''](self[''location''].href)
  445. window.location[''replace''](self[''location''].href)
  446. window[''location''].assign(self[''location''].href)
  447. window[''location''].replace(self[''location''].href)
  448. window[''location''][''assign''](self[''location''].href)
  449. window[''location''][''replace''](self[''location''].href)
  450. self.location[''assign''](self[''location''].href)
  451. self.location[''replace''](self[''location''].href)
  452. self[''location''].assign(self[''location''].href)
  453. self[''location''].replace(self[''location''].href)
  454. self[''location''][''assign''](self[''location''].href)
  455. self[''location''][''replace''](self[''location''].href)
  456. self[''location''][''href''] = location
  457. self[''location''][''href''] = location.href
  458. self[''location''][''href''] = window.location
  459. self[''location''][''href''] = self.location
  460. self[''location''][''href''] = window.location.href
  461. self[''location''][''href''] = self.location.href
  462. self[''location''][''href''] = location[''href'']
  463. self[''location''][''href''] = window[''location'']
  464. self[''location''][''href''] = window[''location''].href
  465. self[''location''][''href''] = window[''location''][''href'']
  466. self[''location''][''href''] = window.location[''href'']
  467. self[''location''][''href''] = self[''location'']
  468. self[''location''][''href''] = self[''location''].href
  469. self[''location''][''href''] = self[''location''][''href'']
  470. self[''location''][''href''] = self.location[''href'']
  471. location.assign(self[''location''][''href''])
  472. location.replace(self[''location''][''href''])
  473. window.location.assign(self[''location''][''href''])
  474. window.location.replace(self[''location''][''href''])
  475. self.location.assign(self[''location''][''href''])
  476. self.location.replace(self[''location''][''href''])
  477. location[''assign''](self[''location''][''href''])
  478. location[''replace''](self[''location''][''href''])
  479. window.location[''assign''](self[''location''][''href''])
  480. window.location[''replace''](self[''location''][''href''])
  481. window[''location''].assign(self[''location''][''href''])
  482. window[''location''].replace(self[''location''][''href''])
  483. window[''location''][''assign''](self[''location''][''href''])
  484. window[''location''][''replace''](self[''location''][''href''])
  485. self.location[''assign''](self[''location''][''href''])
  486. self.location[''replace''](self[''location''][''href''])
  487. self[''location''].assign(self[''location''][''href''])
  488. self[''location''].replace(self[''location''][''href''])
  489. self[''location''][''assign''](self[''location''][''href''])
  490. self[''location''][''replace''](self[''location''][''href''])
  491. self.location[''href''] = location
  492. self.location[''href''] = location.href
  493. self.location[''href''] = window.location
  494. self.location[''href''] = self.location
  495. self.location[''href''] = window.location.href
  496. self.location[''href''] = self.location.href
  497. self.location[''href''] = location[''href'']
  498. self.location[''href''] = window[''location'']
  499. self.location[''href''] = window[''location''].href
  500. self.location[''href''] = window[''location''][''href'']
  501. self.location[''href''] = window.location[''href'']
  502. self.location[''href''] = self[''location'']
  503. self.location[''href''] = self[''location''].href
  504. self.location[''href''] = self[''location''][''href'']
  505. self.location[''href''] = self.location[''href'']
  506. location.assign(self.location[''href''])
  507. location.replace(self.location[''href''])
  508. window.location.assign(self.location[''href''])
  509. window.location.replace(self.location[''href''])
  510. self.location.assign(self.location[''href''])
  511. self.location.replace(self.location[''href''])
  512. location[''assign''](self.location[''href''])
  513. location[''replace''](self.location[''href''])
  514. window.location[''assign''](self.location[''href''])
  515. window.location[''replace''](self.location[''href''])
  516. window[''location''].assign(self.location[''href''])
  517. window[''location''].replace(self.location[''href''])
  518. window[''location''][''assign''](self.location[''href''])
  519. window[''location''][''replace''](self.location[''href''])
  520. self.location[''assign''](self.location[''href''])
  521. self.location[''replace''](self.location[''href''])
  522. self[''location''].assign(self.location[''href''])
  523. self[''location''].replace(self.location[''href''])
  524. self[''location''][''assign''](self.location[''href''])
  525. self[''location''][''replace''](self.location[''href''])
  526. location.reload()
  527. location[''reload'']()
  528. window.location.reload()
  529. window[''location''].reload()
  530. window.location[''reload'']()
  531. window[''location''][''reload'']()
  532. self.location.reload()
  533. self[''location''].reload()
  534. self.location[''reload'']()
  535. self[''location''][''reload'']()

更多关于JavaScript的文章推荐

  • 如何使用异或(XOR)运算找到数组中缺失的数?
  • 如何使用Three.js制作全息交互效果
  • JavaScript闭包是如何工作的?
  • 如何使用JavaScript重定向到其他网页?
  • 如何实现链接悬停显示图像效果?

参考

  • location = location

javascript - 第二次ajax提取页面的时候,main.js没有重新加载,或者说,所有的js都没有重新加载的问题

javascript - 第二次ajax提取页面的时候,main.js没有重新加载,或者说,所有的js都没有重新加载的问题

效果图:
javascript - 第二次ajax提取页面的时候,main.js没有重新加载,或者说,所有的js都没有重新加载的问题
在使用ajax做抽屉的效果时,第二次ajax提取页面的时候,js没有重新加载,怎么解决这个问题?

回复内容:

效果图:
javascript - 第二次ajax提取页面的时候,main.js没有重新加载,或者说,所有的js都没有重新加载的问题
在使用ajax做抽屉的效果时,第二次ajax提取页面的时候,js没有重新加载,怎么解决这个问题?

我的博客使用了类似的pjax技术,当初设计也遇到了类似的问题。

其实根本原因不在于js没有重新加载,其实他根本不需要重新加载,因为已经被加载过了。
根本原因在于其不会被重新执行。

你可以定义个文件叫bootstrap.js。
然后在里面逐个重新执行一遍需要重新加载的js即可。
ps 如果以前有写在公共区域的代码,即不属于任何函数的,需要你自行封装到一个函数里面,然后在这里执行。
比如:
a.js

立即学习“Java免费学习笔记(深入)”;

console.log(''test'');
登录后复制

这个js其实被加载过了,也执行过了,正常情况下是不会再执行了。
那么你就需要修改它为
a.js

var initAJs=function(){
    console.log(''test'');
}
登录后复制

然后在pjax成功返回的时候执行
initAjs即可。

javascript – 使用jQuery在页面加载时将字符串添加到url?

javascript – 使用jQuery在页面加载时将字符串添加到url?

我正在尝试在页面加载时将此特定字符串添加到我的URL的末尾:

?aa_campaign = f45632

(http://examplesite.com/test.html)

它用于营销和跟踪.

我试过这个:

if window.location.href.indexOf("http://examplesite.com/test.html") {
  window.location = "http://examplesite.com/test.html?aa_campaign=f45632";
}

直接上升不起作用,但这个想法是我正在寻找的.有什么想法吗?

解决方法

不需要jQuery,你可以在大多数“现代”浏览器中用纯JavaScript做到这一点,即:
if (window.location.href  === "http://examplesite.com/test.html") {
    window.history.pushState("object or string","Title","http://examplesite.com/test.html?aa_campaign=f45632");
}

pushState()方法

pushState() takes three parameters: a state object,a title (which is
currently ignored),and (optionally) a URL. Let’s examine each of
these three parameters in more detail:

06001

the user navigates to the new state,a popstate event is fired,and
the state property of the event contains a copy of the history entry’s
state object.

06002

after the user restarts the browser,we impose a size limit of 640k
characters on the serialized representation of a state object. If you
pass a state object whose serialized representation is larger than
this to pushState(),the method will throw an exception. If you need
more space than this,you’re encouraged to use sessionStorage and/or
localStorage.

06003

against future changes to the method. Alternatively,you Could pass a
short title for the state to which you’re moving.

06004

pushState(),but it might attempt to load the URL later,for instance
after the user restarts the browser. The new URL does not need to be
absolute; if it’s relative,it’s resolved relative to the current URL.
The new URL must be of the same origin as the current URL; otherwise,
pushState() will throw an exception. This parameter is optional; if it
isn’t specified,it’s set to the document’s current URL.

SRC:https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history

javascript – 使用jQuery重新加载特定元素

javascript – 使用jQuery重新加载特定元素

我正在尝试使用jQuery重新加载按钮上的特定元素,但是当我单击按钮时,整个页面将加载到此元素中.我尝试了以下代码,在此元素中加载整个页面.我想只加载特定元素.

<script>
    $(document).ready(function() {
        $("#button").click(function() {
            $("#demo").load(location.href + "#demo");
        });
    });
</script>
</head>

<body>
    <div id="example">
        <p id="demo">hi</p>
        <button id="button" type="button">press</button>
    </div>

解决方法

您可以将 load()与选择器一起使用.

$("#demo").load(location.href + " #demo"); // Add space between URL and selector.
                                 ^

这将仅加载location.href URL中的#demo元素.

今天关于使用JavaScript更改重新加载时当前页面的URLjs实现页面重新加载的介绍到此结束,谢谢您的阅读,有关535种使用JavaScript重新加载页面的方法、javascript - 第二次ajax提取页面的时候,main.js没有重新加载,或者说,所有的js都没有重新加载的问题、javascript – 使用jQuery在页面加载时将字符串添加到url?、javascript – 使用jQuery重新加载特定元素等更多相关知识的信息可以在本站进行查询。

本文标签: