SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member MatthijsKadijk's Avatar
    Join Date
    Oct 2003
    Location
    Netherlands
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question cycle thru external result pages

    I have a problem including externally generated search result pages in a completely dynamicly build JS page.

    The page consists of blocks of links which can be opened/closed by the user (settings are stored in a cookie). I include an external piece of JS using a simple contruct like:
    HTML Code:
    <script src="http://startpagina.elprincipio.net/mkstat/esp/espotxml.php?keyword=internet&page=1" language="JavaScript"></script>
    What I'd like to do is to make a link to the next (and previous) pages by changing the page parameter (page=2, page=3 etc.) I cannot figure out how to access and change (using JS) the src attribute of the script tag in the current document.

    Some ideas ?

    The complete page I am working on is now online at http://startpagina.elprincipio.net/s...ndex_test.html



    Matthijs Kadijk
    www.elprincipio.com

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script name="sgi" id="sgi" src="furble" language="Javascript" type="text/JavaScript"></script
    
    <script language="Javascript">
    document.getElementById('sgi').src="furble2";
    </script>
    Of course you shouldn't just use getElementById... use whatever safe mechanism you currently use to safely find an element in all browsers ( Though admittedly some browsers could find their bottom a map and their hands in their back pockets ).

    HTH

    G
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    SitePoint Member MatthijsKadijk's Avatar
    Join Date
    Oct 2003
    Location
    Netherlands
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have been working on Flawless_koder suggestion for the
    past view hours, I come close the what I need but not quite...

    I used the document.all.item() method to access the src attribute
    and it seems to work, but the page does not change at all !!

    Code:
    <script name="esp" id="esp" src="http://startpagina.elprincipio.net/mkstat/esp/espotxml.php?keyword=internet&page=1" language="JavaScript"></script>
    
    <script language="Javascript">
    function esp_next(id,page,keyw){
    document.all.item('esp').src="http://startpagina.elprincipio.net/mkstat/esp/espotxml.php?keyword="+keyw+"&page="+page;
    }
    </script>
    
    <a href=JavaScript:esp_next("esp","2","internet")> next page(2)</a>
    <a href=JavaScript:esp_next("esp","3","internet")> next page(3)</a>
    What happens is that indeed the src of the script is changed, I also
    know that the php file was hit at the server, but the page does not change at all ??

    adding a
    Code:
    top.location=top.location
    to force a rewrite does not help. Anny ideas how to make sure the
    JS is reinterpreted without overwritting it with the original code ??

    Matthijs

  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The location won't be changed if you don't change it.

    You could do window.refresh IIRC if you just want to refresh it.

    Use an alert() in the source of those js/php files to check it's being run properly.

    G
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  5. #5
    SitePoint Member MatthijsKadijk's Avatar
    Join Date
    Oct 2003
    Location
    Netherlands
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have tried the window.refresh call in the next_page() function. BUT again nothing happens !

    I included some alerts to check it, and all seems to be fine.

    In stead of manipulating the src attribute of the script tag I tried the same with a HREF attribute of a A tag like this:
    HTML Code:
    <a id="test" href="test">test link</a>
    <script language="Javascript">
    function test_next(id,page,keyw){
    document.all.item('test').href="http://startpagina.elprincipio.net/mkstat/esp/espotxml.php?keyword="+keyw+"&page="+page;
    	//window.refresh;
    }
    </script>
    
    <a href=JavaScript:test_next("esp","2","internet")> next page(2)</a>
    This works fine (without the window.refresh) I can see the HREF change by clicking on the "next page" link ...

    Maybe the script tag need some special treatment ???

    Matthijs

  6. #6
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're confused.

    Lose the window.refresh completely.

    When you change the src of the script - that new src should be loaded automatically.
    1) Check it is called on the server
    2) Put a simple alert in that new src file, if it alerts then you're in business
    3) If not - then you should call the url you're replacing it with manually and look at it to see if it's valid Javascript.

    Use Mozilla to detect errors.

    G
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  7. #7
    SitePoint Member MatthijsKadijk's Avatar
    Join Date
    Oct 2003
    Location
    Netherlands
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I am confused indeed !!
    And getting more confused now ...

    following your suggestions I put some allerts in de included JS (from the PHP file). And indeed the JS is correct (it works fine the first time it is included !!)

    Now if I call the next_page() function I observe the following:
    - the src attributed is changed correctly (we knew this)
    - the php file is correctly called
    - the external scripts gets executed (the allerts are triggered)
    - but ...
    ... nothing changes !!

    I tried the following: I added a
    Code:
    document.title='hello from php $page'
    line into the php file that serves the JS. Indeed the title DOES CHANGE.

    It seems however that any document.write() calls
    do not to have any effect !!

    I am puzzled !!

    Any suggestions ?
    Should the document be reopend ??

    BTW it works in IE, Mozilla seems not to work, but thats not to worry about today...

  8. #8
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.all is IE only

    use document.getElementById instead.

    Or, as flawless pointed out, abstract it to something with a broader reach
    Code:
    document.getNode = function( id )
    {
       return ( document.layers ) ? document.layers[id] : ( document.getElementById || document.all )( id );
    }
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

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