Click to See Complete Forum and Search --> : Opening link in popup through PHP


popcop
05-13-2005, 07:30 PM
I want to use javascript to open a popup window with news which is pulled from the database by PHP

this si that javascript...

=================================================

<script language="JavaScript">
<!--

function open_read(inUrl)
{
winLeft = (screen.availWidth-340)/2;
winTop = (screen.availHeight-450)/2;

if (navigator.appName == "Microsoft Internet Explorer") {
strWindow = "toolbar=no,location=no,status=no,directories=no,menubar=no,scrollbars=auto,resizable=no,width=340,he ight=450,left="+winLeft+",top="+winTop
} else {
strWindow = "toolbar=no,location=no,status=no,directories=no,menubar=no,scrollbars=auto,resizable=no,width=340,he ight=450,screenX="+winLeft+",screenY="+winTop
}

window.open(inUrl, "read", strWindow);

}

//-->

</script>

======================================================

and this is the PHP code im using to for the link

<a href='read.php?id={$data['id']}' target='news');return false;'>{$data['header']}</a>

that piece of code is to open the news page in an iframe called 'news' but how can i change that piece of PHP code so that it links to the javascript and opens in a popup window ????

thanks

neur0maniak
05-14-2005, 05:47 AM
It's a bad Idea to use HTML tags with the apostrophe when using javascript, it just makes things very confusing.

From the "PHP Code" you posted, I'm assuming you mean that it is the content of a PHP Variable that contains the link or just being output via a print command. In either case, I don't know why you have added " );return false;' " in there.

But, if you want to use Javascript inplace of a link, you should make the A Tag look a little more like:

$link = "<a href=\"javascript:;\" onClick=\"open_read('read.php?id={$data['id']}');\">{$data['header']}</a>"

It's a bad idea to have the javascript code directly in the HREF section as I know in Firefox it will return the RESULTS of the javascript execution as the next page.

scragar
05-14-2005, 07:14 AM
I made a PHP news page(veiw it here (http://scragar.mybesthost.com/main.php?s=new_news) - site still very much under construction, so don't play around too much on the other pages. new News is not the same as the main page, the main page is hand coded because of an error in the origional database system), you could use that if you wanted, it works both with and without javascript, even if the user has an old version that doesn't understand document.getElementsByTagName