Monday, August 23, 2010

How to open multiple links in new tabs, using javascript

I wanted to click a button, and have several new browser tabs open to specific websites.

This seems to work in Firefox 3.0.19, but not in IE8.

Any suggestions on a solution for both browsers?

<script language="javascript">
window.open('http://www...', '1 _newtab');
window.open('http://www...', '2 _newtab');
window.open('http://www...', '3 _newtab');
</script>

Monday, August 16, 2010

How to remove unused GET parameters from a page's URL

I've several pages that accept numerous GET parameters from the URL, but sometimes few if any of these parameters are provided. I want to strip the blank parameters from the URL and direct the browser to that link, so that the URL is more readable, and so that users may copy and paste or bookmark a more concise URL.

Near the top of my PHP script I call the shrink_url() function, which I have preloaded with a require_once("funcs.php") statement.  funcs.php includes this function:

function shrink_url()
{
    $currenturl =curPageURL();
    $servername = $_SERVER["SERVER_NAME"];
    $scriptname = $_SERVER["SCRIPT_NAME"];
    foreach ($_GET as $key => $value)
    {
        if ($value <> "") {$getparams .= "&" . $key . "=" . urlencode($value);}
    }
    $getparams = substr($getparams,1);
    if ($getparams <> "") $getparams = "?" . $getparams;
    $redirect = "http://" . $servername . $scriptname . $getparams;
    if ($currenturl <> $redirect)
    {
        ob_end_clean(); //stops loading the current page.
        header("Location: $redirect"); //redirects to the shrunken URL.
    }
}

Thursday, August 12, 2010

PHP CURL

Sending POST form data with php CURL
This brief guide explains 2 different reasons for wanting to send POST data with curl and how to do it. It is very handy to have the abililty to arbitrarily send POST data from a form to a script.

This site also has links to resources on Ajax, CSS, Javascript, XHTML, and more.