Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    May 2005
    Location
    California
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    pull a javascript variable from other page

    hi
    i have 2 pages, one have two javascript variables assigned, lets say...
    Code:
    PAGE 1:
    <script>navnext = 1</script> 
    <script>navlen = 7</script>
    
    PAGE2:
    how can i pull the PAGE1 variable values?
    note1: also my two pages are in the same domain.

    note2: i know that the PASSING method using SUBMIT button works well in this cases, but the thing is that i wont pass the variable... i want to pull the variable...
    only using javascript or DOM, no dinamic php either asp...

    i tried to changing the context of the page like
    Code:
    <base href='http://mypage.domain/' target='_self'>
    with no results, also i need to call the same pair of variable of too many pages from the same page...

    any javascrip or DOM idea?

    thanks members

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Please take a look at the following page(s) about tranferring data to another page, it may help you out.

    http://www.huntingground.freeserve.c...ta/p_data1.htm
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    New Coder
    Join Date
    May 2005
    Location
    California
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    at this moment i will give it a read

    thanks!!

  • #4
    New Coder
    Join Date
    May 2005
    Location
    California
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, this is the panorama: i have a yah_oo-store, and i cannot use dynamic scripts inside orpduct pages, this time im doing a "Special Items page By Department", and it its a simple page with links to each page wich have special items, things become hard since, each page wich have special items have a link like : http://www.mypage.mydomain/departmen...html?pageNum=5, because i have a javascript dynamic pagination wich load only the items marked as "special" in the current department page
    actually i have like options:

    1- load the pages by iframes and then get the variable values (slown loading time)
    2- create a template wich recalculate the variable values and pull it by a .js include, (daily upload)
    3- recalculate the variable values inside the pulling page (hard to coding), no daily updates, once published is fast loading

    thanks for the advising

  • #5
    JPM
    JPM is offline
    Regular Coder
    Join Date
    Mar 2004
    Location
    Norway
    Posts
    204
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dont think there is another way to pass variables with javascript than doing something like this

    page1
    Code:
    <script>
     var test = "somevalue";
     document.location.href ="test.html?"+test;
    </script>
    page2
    Code:
     var test = document.location.href;
     var i = test.indexOf("?");
     test = test.substring(i+1,test.length);
    
     alert(test);
    <JPM />

  • #6
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Usually you would go

    <script type="text/javascript">
    <!--
    if (location.search.length > 0)
    dataPassed = unescape(location.search.substring(1));
    alert(dataPassed)
    //-->
    </script>

    in page 2
    Last edited by Mr J; 05-21-2005 at 08:31 PM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #7
    New Coder
    Join Date
    May 2005
    Location
    California
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i cannot figureout how could it work...
    i hope this way:

    variable source page:
    page name: test1.html
    Code:
    <script>
     var test = "pageNum=4"; // this is the variable i need: pageNum
     document.location.href ="test.html?"+test;  // why change the location?
    </script>

    pulling page:
    page name: test2.html
    Code:
    <script>
     var test = document.location.href;
     var i = test.indexOf("?");        // what is supposed to do this code?
     test = test.substring(i+1,test.length);
     alert(test);    // print the current url...
    </script>
    it just prints the current url...


    in this sample you provided me: have i to load first the source page, and then the calling page?, if yes, this is a passing variable code...

    if no, then this is a pulling variable code...

    wich one is?

    thanks!
    Last edited by sugar2; 05-21-2005 at 08:41 PM.

  • #8
    New Coder
    Join Date
    May 2005
    Location
    California
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Mr J
    Usually you would go

    <script type="text/javascript">
    <!--
    if (location.search.length > 0)
    dataPassed = unescape(location.search.substring(1));
    alert(dataPassed)
    //-->
    </script>

    in page 2

    since i working here with location.search i belive i have to load the first page before load the seccond one...

    is there a way to call the variable value without load the page first?


    thanks guys

  • #9
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Not with javascript
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #10
    Regular Coder
    Join Date
    Jul 2002
    Location
    Canada, eh?
    Posts
    133
    Thanks
    2
    Thanked 3 Times in 3 Posts
    If you want to load variables from any source, then shove them all in an external .js file, and call the file like so:

    Code:
    <script src="path/to/the/file.js" type="text/javascript"></script>
    If you want to pass variables from one page to another, then use the DOM:

    test.html:
    Code:
    <script type="text/javascript">
    
    document.myVar = 32;
    
    window.open('test2.html','some_name','');
    
    </script>
    test2.html:
    Code:
    <script type="text/javascript">
    
    v = window.opener.document;
    
    alert('I do declare that myVar is equal to '+v.myVar+'.');
    
    </script>

  • #11
    New Coder
    Join Date
    May 2005
    Location
    California
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks Eternity Angel, but i think Mr J has the reason, since its imposible to load like 30 new windows, only to load a page wich pull their 60 variables..

    i think the solution is:

    1- Put a simple link in the calling page, and in the link page put a javascript wich look if its page is called from certain page and then if yes, redirect to the proper URL, and if not, let it load.
    i mean like that:
    PSEUDOCODE:
    Code:
    <SCRIPT> 
    
    NO WORKING
    
    if   (document.referrer = "http://store.crafta.com/specials-by-department.html") 
          location.href = "?pageNum=5"; 
    
    </SCRIPT>
    or 2- Calculate the variables values inside the calling page. (i think this is the better and harder solution...

    thanks everibody

  • #12
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    If the variables do not change then you can do what Eternity Angel suggested.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #13
    New Coder
    Join Date
    May 2005
    Location
    California
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i think is no good practice to open more than 1 pop window per page... and if i do that i should open more than 30 windows...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •