Javascript window.open() passing args

大兔子大兔子 提交于 2019-11-28 12:42:25

问题


I am trying to use window.open() to pass along some arguments to another page.

I want the page to be

myPage.html?img=1.jpg

Where once on that page I will use javascript to get the arg and show the image.

However I cannot figure out how to do this with window.open() cause it says the pages does not exist which I can understand.

 window.open('myPage.html?img=1.jpg','_blank')  

Hope this makes sense and I don't even know if it is possible.


回答1:


myPage.html should exist, and check the docs on window.open

to pass vars:

var variable = "lol";
var w = window.open("http://example.com");
w.variable = variable;

or yopu can visit the opeing window:

var variable = window.opener.variable;


来源:https://stackoverflow.com/questions/6643036/javascript-window-open-passing-args

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!