SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 41

Thread: Popups

  1. #1
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Popups

    I have been trying to create a popup box with pre-set sizes with no scroll bars etc for my headlines, but for some reason it just won't work for me.

    Has anyone used javascript popup in PHP ? if so I would love to know how this was implemented !

    Here's the headlines script i would like the popups to work with...


    PHP Code:
    <?php
      
    // includes
    include("conf.php");

    // open database connection
    $connection mysql_connect($host$user$pass) or die ("Unable to connect!");

    // select database
            
    mysql_select_db($db) or die ("Unable to select database!");

    $ocnews = @mysql_query('SELECT ID, headline, DATE_FORMAT(date,\'%W %D %M \') AS realdate, content, author FROM ocnews ORDER BY author DESC LIMIT 5'); 
    if (!
    $ocnews) { 
    die(
    '<p><font color="red" size="2" face="Arial, Helvetica, sans-serif">Error retrieving news from database!</font><br />'
    'Error: ' mysql_error() . '</p>'); 


    while (
    $author mysql_fetch_array($ocnews)) { 
           
    $id $author['ID']; 
           
    $headline htmlspecialchars($author['headline']); 
           
    $date $author['realdate']; 
           
    $content htmlspecialchars($author['content']); 
           
    $author htmlspecialchars($author['author']); 
      echo(
    "<table width='230' border='0' cellpadding='0' cellspacing='0'>
      <!--Table-->
      <tr> 
      <td width='230' height='16' valign='top' bgcolor='#FFFFFF'><font size='2' color='#000000' face='Arial, Helvetica, sans-serif'>- <a href='article.php?id=
    $id' target='_blank'> $headline</a></font><font size='1' color='#000000' face='Arial, Helvetica, sans-serif'><img src='News/images/spacer.gif'width='10' height='4'>$date</font></td>
      </tr>
      </table>
         "
    );
    }

    ?>

    Best Regards
    Deano

  2. #2
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not simply use Javascript from the parent window to open the pop-up with the above script as the web page ?

    You can only create content dynamically using PHP for Javascript to use, and not the other way around 8)

  3. #3
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    well the open window js function is this
    Code:
    <script language="javascript">
    <!--
    window.open("mail.php",null,"height=250, width=250");
    -->
    </script>
    and then your code could be a single page called mail.php and it would open up in a new page?

    Sarah
    Regular user

  4. #4
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx for the help Sarah,Dr Livingston I will give it a try

    Best Regards
    Deano

  5. #5
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm now i cant get the headlines displayed so that i can click on the headline opening the new window for the headline content ?
    PHP Code:
    <?php
      
    // includes
    include("conf.php");

    // open database connection
    $connection mysql_connect($host$user$pass) or die ("Unable to connect!");

    // select database
            
    mysql_select_db($db) or die ("Unable to select database!");

    $ocnews = @mysql_query('SELECT ID, headline, DATE_FORMAT(date,\'%W %D %M \') AS realdate, content, author FROM ocnews ORDER BY author DESC LIMIT 5'); 
    if (!
    $ocnews) { 
    die(
    '<p><font color="red" size="2" face="Arial, Helvetica, sans-serif">Error retrieving news from database!</font><br />'
    'Error: ' mysql_error() . '</p>'); 


    while (
    $author mysql_fetch_array($ocnews)) { 
           
    $id $author['ID']; 
           
    $headline htmlspecialchars($author['headline']); 
           
    $date $author['realdate']; 
           
    $content htmlspecialchars($author['content']); 
           
    $author htmlspecialchars($author['author']); 
      echo(
    "
      <table width='230' border='0' cellpadding='0' cellspacing='0'>
      <tr> 
      <td width='230' height='16' valign='top' bgcolor='#FFFFFF'>
      <font size='2' color='#000000' face='Arial, Helvetica, sans-serif'>- 
      <script language='javascript'> window.open('article.php?id=
    $id',$headline </a>,null,'height=250, width=250' ); </script></font>
      <font size='1' color='#000000' face='Arial, Helvetica, sans-serif'>
      <img src='News/images/spacer.gif'width='10' height='4' border=0>
    $date</font></td>
      </tr>
      </table>
      "
    );
    }

    ?>
    any ideas?

    thx Deano

  6. #6
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try
    PHP Code:
    echo(
    <table width='230' border='0' cellpadding='0' cellspacing='0'> 
      <tr> 
      <td width='230' height='16' valign='top' bgcolor='#FFFFFF'> 
      <font size='2' color='#000000' face='Arial, Helvetica, sans-serif'>- 
      <a href=\"javascript: window.open('article.php" 
    .$id ."', null, 'width=500,height=500')\">"$headline ."</a>
      </font> 
      <font size='1' color='#000000' face='Arial, Helvetica, sans-serif'> 
      <img src='News/images/spacer.gif'width='10' height='4' border=0>"
    $date "</font></td> 
      </tr> 
      </table>
    ); 
    - website

  7. #7
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    note that the 'java script' in the middle is one word, vB seems to be messing me up!
    - website

  8. #8
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm this is what i get dsiplayed once clicked the headline

    You don't have permission to access /public/News/java script: window.open('news.php45', null, 'width=500,height=500') on this server.

    very strange !

  9. #9
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by website
    note that the 'java script' in the middle is one word, vB seems to be messing me up!

    As website said, it should be javascript.
    Mike
    It's not who I am underneath, but what I do that defines me.

  10. #10
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The space isn't the problem since I've assumed you've typed it as one whole word ?

    The solution from website is in error I'd say ?

    PHP Code:
    <font size='2' color='#000000' face='Arial, Helvetica, sans-serif'>- 
      <
    a href=""\"javascript: window.open('article.php?id=" .$id ."', null, 'width=500,height=500')\">"$headline ."</a> 
      </font> 
    Though I don't think this is the problem since if it did work you'd only have a problem reading the variable from $_GET.

    There is something more sinister at play here 8) Somehow your URL is getting screwed since the Javascript is somehow getting attached to it...

    Sorry don't know why but try the fix I gave first to see if that helps.

  11. #11
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your finished URL should be like:

    PHP Code:
    access/public/News/article.php?id=33 
    So it might have been website's error ?

  12. #12
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no I belivet it is not, the reason why javascript is getting in the url is because it is in 2 words, if it would be in one word the browser would realise it is javascript!

    Deano, simply remove the space between 'java' and 'script' so it will become 'javascript'
    - website

  13. #13
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    lets wait until Dean gets back with what happen sif he removes the space - if that doesn't work we can look at it again

    Sarah
    Regular user

  14. #14
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay - no offence was intended btw website - no hard feelings ? none on my part anyways 8)

  15. #15
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why are you using that ugly href anyway? what's wrong with a good old fashioned onclick?

    Code:
    <a href="#" onClick="window.open();return false;">
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  16. #16
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm getting there slowly !
    PHP Code:
    echo(
    <table width='230' border='0' cellpadding='0' cellspacing='0'> 
      <tr> 
      <td width='230' height='16' valign='top' bgcolor='#FFFFFF'> 
      <font size='2' color='#000000' face='Arial, Helvetica, sans-serif'>- 
      <a href=\"java(nospace)script: window.open('article.php" 
    .$id ."', null, 'width=500,height=500')\">"$headline ."</a> 
      </font> 
      <font size='1' color='#000000' face='Arial, Helvetica, sans-serif'> 
      <img src='News/images/spacer.gif'width='10' height='4' border=0>"
    $date "</font></td> 
      </tr> 
      </table> 
    ); 
    ok.. the link now works and displays a new window, but.... in the new window no such file blah blah, then once the window has been closed the original page ie (headlines) now shows exactly this [object] very odd !

    Best Regards
    Denao

  17. #17
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ummm....
    PHP Code:
    # start of your TABLE structure goes here
    <a href="#" OnClick="window.open('article.php?id=<?php echo($id); ?>', null, 'width=500, height=500');"><?php echo($headline); ?></a>
    # remainder of TABLE structure goes here
    Is that any better ? Surely somethings got to give no ?

    -- EDIT --

    You will need to break out of PHP to put in your TABLE BTW 8) Do notice the ECHOs in there ? LoL

  18. #18
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Okay - no offence was intended btw website - no hard feelings ? none on my part anyways 8)
    Well, ok, no hard feelings here too, but simply I have been using the exact line in my websites and it never breaks (without the php though...)
    why are you using that ugly href anyway? what's wrong with a good old fashioned onclick?
    Not that I am a javascript expert but does it matter?
    ok.. the link now works and displays a new window, but.... in the new window no such file blah blah, then once the window has been closed the original page ie (headlines) now shows exactly this [object] ?
    ok, yes Livingstone was right in that there is missing part here
    PHP Code:
    <a href=\"java script: window.open('article.php" .$id ."', null, 'width=500,height=500')\">"$headline ."</a> 
    while it should be
    PHP Code:
    <a href=\"java script: window.open('article.php?id=" .$id ."', null, 'width=500,height=500')\">"$headline ."</a> 
    My apologies!

    also if you would like it to be just the box and no scroll bars etc try this:
    PHP Code:
    <a href=\"java script: window.open('article.php?id=" .$id ."', null, 'width=500,height=500,status=no,scrolling=no,resizable=yes,scrollbars=no')\">"$headline ."</a> 
    Then you modify the height, width, status etc as you want it to be.

    but why the name of the headline changes to [object] I have abselutely no clue.... Is it still going on with the new part?

    Hope that helps.
    - website

  19. #19
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok hmmm, the links work, the headline contents opens in a new window but the [object] replaces the headlines page ?

    http://www.ops-centre.co.uk/squadron...headlines2.php

    Cheers Deano

  20. #20
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is, the most wierdest thing I have ever seen....
    - website

  21. #21
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the link - now that I've had a look I've seen this before - my early Javascripts LoL.

    But it's been this long... the problem is that I think Javascript is looking for something to be returned upon opening the window ?

    I suppose you could try the following,

    PHP Code:
    OnClick="window.open('article.php?id=<?php echo($id); ?>', null, 'width=500, height=500');return true;"
    If that didn't work, change the

    PHP Code:
    ...return true
    To

    PHP Code:
    ...return false
    Failing that you could post your script within the Javascript forums to see if someone knows more on using pop ups ?

  22. #22
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would just like to say thx to everyone that has responded to my cries for help

    The script now works fine accept for the headlines page now changes to [object], after I implemented the return false/true.

    here's the code so far if anyone has any other ideas

    PHP Code:
    <a href=\"javascript: window.open('article.php?id=" .$id ."', null, 'width=400,height=200,status=no,scrolling=no,resizable=yes,scrollbars=no;return false;')\">"$headline ."</a> </font> 
    Thx again all for your help !! if i manage to reslove this issue successfully I will post the revised script here for you to take a look at !

    Best Regards
    Deano

  23. #23
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all, ok this is the script so far.. with the headlines page not showing [object] now

    PHP Code:
    <a href="article.php?id=$idtarget="_blank" onclick="window.open( this.href, this.target, \'width=400, height=455\' ); return false;"
             
    $headline</a><img src="News/images/spacer.gif"width="10" height="4" border="0">$date<br
    althought the new window retains the exact layout i need, all i get dsiplayed now instead of the headlines is this :

    $headline $date
    $headline $date

    and when i click on the headline the page appears blank ? except for the pre-formated areas i added.

    any ideas ?

    Cheers Deano

  24. #24
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    might be something because of the way you use the ' and " or/and the echo() command. Can you post the full code please.
    - website

  25. #25
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's doing it because essentially you are *******ising a the href tag. Try this

    Code:
    <a href="java script: window.open('article.php?id=" .$id ."', null, 'width=500,height=500,status=no,scrolling=no,resizable=yes,scrollbars=no'); return false;\">". $headline ."</a>
    that may stop it happening...
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky


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
  •