Forums Archive Index > Cool free scripts > v-newsticker problem

Author: marcphisto

Date: 16 Jun 2005 9:25 am

Hi,

I am populating my news ticker with items from a database.

What I want to do is to have the news item pop up rather than appear in a normal web page.

I have got as far as getting the popup working (as in it appears).

My problem is that when the popup appears my main browser window shows [object Window] on a blank page and javascript:window.open("popupcremonews.php?article=3","cremonews","width=350,height=500,scrollbars=yes,toolbar=no"); appears in the address bar.

How do I stop main window from going anywhere? i.e. I want to keep it on the page it is currently on.

the development site is --> http://www.splash.ie/dev/cremo

Any ideas would be greatly appreciated!

Code:
                   
                       $query = "SELECT id, date, text, title
                               FROM news
                               WHERE deleted = 'n'
                               ORDER BY date DESC
                               LIMIT 5";
                       $result = mysql_query($query);
                       $i = 0;

                    $vcontent = "
                      v_content=[";

                       while ($row = mysql_fetch_row($result))
                    {
                             $date = $row[1];
                             $body = format_event(substr($row[2], 0, 90));
                             $title = substr($row[3], 0, 60) . "...";//stripslashes(substr($row[3], 0, 60) . "...");
                             $day = substr($date, 8, 2);
                              $mon = substr($date, 5, 2);
                              $yar = substr($date, 0, 4);

                              $stamp = mktime(12,0,0,$mon,$day,$yar);
                              $date = date("jS F Y", $stamp);

/*
                              if($i==0)
                            $vcontent .= "['cremonews.php?article=$row[0]','<span class=ticker>$title</span><br><span class=tickerdate color=#999999>$date</span>','']";
                              else
                                  $vcontent .= ",['cremonews.php?article=$row[0]','<span class=ticker>$title</span><br><span class=tickerdate>$date</span>','']";
*/

                              if($i==0)
                            $vcontent .= "['javascript:window.open(\"popupcremonews.php?article=$row[0]\",\"cremonews\",\"width=350,height=500,scrollbars=yes,toolbar=no\");','<span class=ticker>$title</span><br><span class=tickerdate color=#999999>$date</span>','']";
                              else
                                  $vcontent .= ",['javascript:window.open(\"popupcremonews.php?article=$row[0]\",\"cremonews\",\"width=350,height=500,scrollbars=yes,toolbar=no\");','<span class=ticker>$title</span><br><span class=tickerdate>$date</span>','']";

                             $i++;
                       }
                       //mysql_close($link);

                   $vcontent .= "];";


Author: smartmenus

Date: 16 Jun 2005 11:38 am

The window.open() function returns the created window object (which the browser tries to load in your main window) and that's why you can't call it directly like this:

['javascript:window.open("popupcremonews.php?article=3","cremonews","width=350,height=500,scrollbars=yes,toolbar=no");','text','_self']

Here's how to do it:

===
function openPopUp(url,name,features){
window.open(url,name,features);
}

v_content=[
['javascript:openPopUp("popupcremonews.php?article=3","cremonews","width=350,height=500,scrollbars=yes,toolbar=no"','text','_self'], ...
===


Author: marcphisto

Date: 16 Jun 2005 11:48 am

perfect, thanks very much :D