js实现两个页面之间跳转参数传递

html在设计时,规定跳转地址后加"?"表示从此开始为跟随页面地址跳转的参数。

有时候,我们希望获得相应的跳转前页面里的内容,这时候我们就可以考虑将内容以参数形式放到地址中传过来,这里我建议将参数以变量形式传递。

代码案例如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>direct1.html</title>
</head>
<body>
    <div><a id="a1" href="direct2.html">点击此处</div>
    <script>
       var a1=document.getElementById("a1");
       var person={
        name:"Zhuxingyu",
        age:18
       };
       a1.href=a1.href+"?"+person.name;
    </script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>direct2.html</title>
</head>
<body>
    <script>
      var getInfo=window.location.search.slice(window.location.search.lastIndexOf("?")+1);

      console.log(getInfo);
    </script>
</body>
</html>

  

  这样做有两点需要注意,第一,放在地址后的参数只能以字符串格式来传递,我尝试过传递对象,现对象被解析成object后字符串化了,不能识别;第二,多次返回direct1页面跳转会重复加入参数,你可以在direct2中通过正则来截取想要的那部分。

时间: 2024-08-05 21:37:28

js实现两个页面之间跳转参数传递的相关文章

两个页面之间的动画跳转。

接触到了两个页面之间的跳转带动画的.效果还不错. 一,先上项目总体图. 二,上代码. AppDelegate.m文件 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; /

HTML5中window.postMessage,在两个页面之间的数据传递

HTML5中window.postMessage,在两个页面之间的数据传递 2015年11月3日 8536次浏览 关于postMessage window.postMessage虽然说是html5的功能,但是支持IE8+,假如你的网站不需要支持IE6和IE7,那么可以使用window.postMessage.关于window.postMessage,很多朋友说他可以支持跨域,不错,window.postMessage是客户端和客户端直接的数据传递,既可以跨域传递,也可以同域传递. 应用场景 我只

两个页面之间的通信

今天要给大家说的是两个不同页面之间的通信,通过一个拖拽demo来模拟: 首先,写好基础的拖拽代码: <script> window.onload = function() { var oDiv = document.getElementById('div'); oDiv.onmousedown = function(ev) { var ev = window.event || ev; var disX = ev.clientX - oDiv.offsetLeft; var disY = ev.

Android两个页面之间的切换效果工具类

import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Build; import android.widget.Toast; public class ActivityAnimationUtil { private Context context; pr

JS计算两个日期之间的天数

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ

iOS 两个页面之间的跳转

-------->-------->-------->-------->-------->-------->-------->   以上完成页面one跳到页面Two  ,之后从页面Two返回页面One -------->-------->-------->-------->

如何实现两个页面之间进行传值

参考地址:http://blog.csdn.net/hlk_1135/article/details/52809468 B/S页面间通信 HTTP是无状态的协议.Web页面本身无法向下一个页面传递信息,如果需要让下一个页面得知该页面中的值,除非通过服务器.因此,Web页面保持状态并传递给其它页面,是一个重要的技术. Web页面之间传递数据,是Web程序的重要功能 在HTTP协议中一共有4种方法来完成这件事情: 1)URL传值:2)表单传值:3)Cookie方法:4)Session方法: 一.UR

ios两个app之间跳转,传值的实现

两个APP之间的跳转是通过[[UIApplication sharedApplication] openURL:url]这种方式来实现的. 1.首先设置第一个APP的url地址 2.接着设置第二个APP的url地址 3.需要跳转的时候 NSString *urlString = [NSString stringWithFormat:@"AppJumpSecond://%@",textField.text]; [[UIApplication sharedApplication] open

js jquery 实现html页面之间参数传递(单一参数、对象参数传递)

最近自己在忙着做毕业设计,后台程序员,前端菜鸡,因为需要,所以实现了html页面之间参数传递.------jstarseven .菜鸡的自我修养. 页面A代码如下: 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="