如何在重定向完成后执行一些jQuery或JavaScript代码 [英] How to execute some jQuery or JavaScript code after a redirect has completed

查看:111
本文介绍了如何在重定向完成后执行一些jQuery或JavaScript代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果像jQuery / JS重定向那样我怎么能执行jQuery / JS代码...

How can I execute jQuery/JS code as soon as a jQuery/JS redirect like...

$(location).attr('href','/target_path');

...或...

window.location.href = "/target_path";

...已完成加载新页面?

...has finished loading the new page?

具体来说,我需要传递一条警告信息并将其插入并在新页面上显示(包含在某些HTML中)。

Specifically, I need to pass an alert message and insert it into and display it (enclosed in some HTML) on the new page.

推荐答案

重定向后,不可能告诉JavaScript执行某些代码。

It is impossible to tell JavaScript to execute some code after a redirect.

但是你有不同的选择:


  1. 在重定向网址中传递一个字符串,然后在准备就绪上执行某些操作

  2. 将一些信息存储在Cookie中,然后执行某些操作ready

  3. 使用 DOM存储一些数据存储(即 sessionStorage )如果您不介意较小的浏览器支持

  1. Pass a string in the redirect URL and then do something on "ready"
  2. Store some information in a cookie and then do something on "ready"
  3. Store some data using DOM storage (namely sessionStorage) if you don't mind the smaller browser support

这篇关于如何在重定向完成后执行一些jQuery或JavaScript代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆