Hi,

I've a problem with javascript and php links:

What I wanna do:

By means of a hyperlink opening a pop-up window and displaying a php-file (passing the variables i know how to)

Problem: got javascript error

I use following script:

<HEAD> 
<script> 
function openpopup(){ 
var popurl="news/news_display.php" 
winpops=window.open(popurl,"","width=500,height=200,") 
} 
</script> 
</HEAD> 

And I use the following link:

<?php echo "<a class=news href=javascript:openpopup()?news_id=" . $news['news_id'] .">" . 'More ...' ?></a> 

Can someone be so kind to help me with this ?

Thanks in advance,

Gijs

    Just create a complete Script in your href..:

    <?php
    $openmsg="news/news_display.php?news_id=".$news['news_id'];
    ?>

    <a href="javascript: window.open('<?=$openmsg ?>', '', 'toolbar=no, location=no ,directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=640, height=480'); void('');">
    <li>...more...</li></a>

      Does it work if you just hardcode the HTML? I'd try it without having php generate the <a ...></a> tag first, then compare what works to what was echoed by viewing the source.

        Hi KoshNaranek,

        First a little explanation:
        when I use href target=_blank the whole show works perfectly.

        Now to your suggestion:
        I gave it a couple of tries , but got an error that the page could not be found.

        I started looking and saw that in the message line with your example there was something like this:

        ?news_id=30[COLOR=red]'[/COLOR], etc..

        I think the " ' " was causing the error, so I left out the " ' " around <?=$openmsg ?>.

        Result: the "news_id" didn't show up any longer an produced an error.

        Could You help me some more with this ?

        Thanks in advance,

        Gijs

          Run the script, use the browser to view the resulting source; you may see what's wrong there.

          Failing that, use a decent Javascript debugger (Mozilla has one; IE doesn't) and see what it claims the fault is.

            Try using :

            <?php 
            $openmsg="news/news_display.php?news_id=".$news['news_id'];
            
            print("<a href=\"java script: window.open('$openmsg', '', 'toolbar=no, location=no ,directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=640, height=480');\">here</a>");
            
            ?>
            

            Might work....

            Oops - I should learn to finish my lines... "); "); "); "); I'll get there sooner or later....

              Hi,

              Basicly, if I understand correctly this should to do same thing as your first suggestion.

              Tryed it but ... noops ....

              Same thing happens as with the first code ๐Ÿ™

              Thanks anyway,

              Gijs

                OK - a different type of suggestion...

                <?php
                $openmsg="news/news_display.php?news_id=".$news['news_id'];
                print("
                <head>
                <script languagae=javascript>
                <!--hide from old browsers
                function popup () {
                
                window.open('$openmsg', '', 'toolbar=yes, location=yes ,directories=no, scrollbars=yes, resizable=no, copyhistory=no, width=640, height=480');
                }
                -->
                </script>
                </head>
                <body>
                <a href=javascript:popup()>here</a>
                </body>");
                ?>

                Just a suggestion... quite like your first one, but runs fine in my browser....

                  Many Thanks to The Chancer,

                  It works with the latest version... and again it doesn't.

                  I'll try to explain:

                  The pop opens, but doesn't seem to pass the correct $ value.

                  The code is placed in a while loop that lists all of my news articles, but I use a LIMIT in combination with 2 variables:
                  $pos and $count
                  Those $ make that I retrieve only a limited list of 2 articles and are used to create hyperlinks to browse back and forwards tru the list.

                  What's being happening now:
                  the pop-up opens always with the value of of the second news_id
                  listed on the page.
                  So if I click the first hyperllink it opens the second value.
                  So if I click the second hyperlink it opens the correct value.

                  I hope this makes sense to you.

                  I tried listing only 1: then it works fine...
                  I tried listing 3: pic for all of the hyperlinks the value of the last one listed

                  I'm a bit puzzled why allways last value_id is being used for all the hyperlinks.

                  But, let's be realistic, I'm already happy if it works with 1, but sure like to have it work with 2

                  Thanks a lot,

                  Gijs

                    In your header / js include

                    function OpenNews( newsid )
                    {
                    	var newswin = window.open( 'news/news_display.php?news_id=' + newsid, 
                    			'newswin', 'toolbar=no, location=no, directories=no, \
                    			status=no, menubar=no, scrollbars=yes, resizable=yes, \
                    			copyhistory=no,width=600,height=450')			
                    		window.blur()
                    		newswin.focus()
                    	}
                    }
                    

                    and in the HTML:

                    <a href="javascript:OpenNews( '<?php
                    echo $news['news_id'] ?>' )">News</a> 
                    

                      Don't think I need to say any more on that subject. Should work fine now thanks to Daveyboy...

                        Sorry dear folk,

                        not working either, getting the following message:

                        HTTP 404 - File not found
                        Internet Explorer

                        Looked with browser in source code and it states:

                        <a href="java script๐Ÿ˜ฎpenNewsCOLOR=crimson[/COLOR]">News</a>

                        Do these errors help to find the solution ?

                        After 48 hours of trying myself, trying different suggestions and playing around with them, I'm really ready to chuck in the whole "kaboomski" and either go with the Chancer's thing (a least it works with a limited list of 1 item or I'll use a href target=_blank instead op a pop-up)

                        I'm getting depressed being a newbie :mad:

                        Thanks to everybody who was so kind to help me !

                        Best Regards,

                        Gijs

                          Be aware that for reasons best known to itself, vBulletin likes to write "javascript" as two words instead of one...

                            Is it a live page that we can look at ? Would hate to give up now....
                            Either that or upload the code as a text file....

                              My version works perfect in my case-system... :p

                              I think its a real "copy&paste"-Problem :rolleyes: ive changed my post 10ยฒ times... always java_script instead of "oneword" javescript...

                              (del "e" set "a" - just a test ๐Ÿ†’ )

                                Regarding my code above:
                                It does work, but as the venerable Weedpacket points out, the bloody forum has chewed up "javascript" into two words "java" and "script". Fix that an' it should work - I took the code from a site I built and tested on about 8 browsers.

                                  Make sure you dont have any programs that block pop ups !

                                  :p

                                    Hi,

                                    Thanks a lot for encouraging me not to give up.

                                    First to the code of daveyboy:

                                    I understood what our venerable master of the telecaster mr. Weedpacket was saying.
                                    I had changed it to "javascript" but ended up with a "js error". As I'm not allowed to put netscape on my pc, with IE I'm unable to view the js error.

                                    Secondly :
                                    Work with pop-up killer and have it properly configured, my other pop-ups work fine.

                                    Thirdly:
                                    Is not on a server, but I attach my news.inc (in txt) here.

                                    Have to go to work now ...

                                    And thanks again for helping me !

                                    Gijs

                                      Originally posted by gijs
                                      I understood what our venerable master of the telecaster mr. Weedpacket was saying.
                                      I had changed it to "javascript" but ended up with a "js error". As I'm not allowed to put netscape on my pc, with IE I'm unable to view the js error.

                                      You may quote this post in a case to allow it ๐Ÿ™‚

                                      I took your attachment, stripped out the PHP (replacing the bits that echo stuff with boilerplate) to make a plain HTML file - the sort that would be arriving at the browser. I ran it in Mozilla, and the Javascript console announced:

                                      Error: Syntax Error
                                      Source file: news.inc.html Line 14
                                      }

                                      Sure enough the function definition

                                      function OpenNews( newsid )
                                      {
                                      	var newswin = window.open( 'news/news_display.php?news_id=' + newsid, 
                                      			'newswin', 'toolbar=no, location=no, directories=no, \
                                      			status=no, menubar=no, scrollbars=yes, resizable=yes, \
                                      			copyhistory=no, width=600, height=450')			
                                      		window.blur()
                                      		newswin.focus()
                                      	}
                                      }
                                      

                                      has a spurious } on the end. Took that out and it worked.

                                        <nuff said>

                                        If only our eyes were as good at seeing them as a computer...