Pass JavaScript variable between two HTML pages

后端 未结 3 1300
野性不改
野性不改 2021-01-25 17:22

I have this html page, that gathers the movie name and stores it in a JavaScript variable.




        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-25 17:46

    I only present this solution since somebody commented that parsing query strings in JavaScript is a bit cumbersome...and given that I can accomplish want you want in one line of code (without any of the rest of your program having to change that much) you might want to consider this instead:

    var movieName = window.opener.document.getElementById("movieName").value;
    

    Replace the line that used to read `var movieName = getQueryVariable("movieName")' with the one above and that's all there is to it...

    in fact my solution allows you to refactor out now unnecessary code in the first file as well:

    change the ≤script≥ TAG so it reads:

    
    

    ...and as previously mentioned in the second file the ≤script≥ tag will read:

    
    
                                     
                  
提交回复
热议问题