Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open link in Popup Window with Javascript [closed]

I'm trying to load a href into a popup window of specific dimensions which also centers in the screen.

Here is my source:

<li>
    <a class="sprite_stumbleupon" href="http://www.stumbleupon.com/submit?url=http://www.your_web_page_url" target="_blank" onclick="return windowpop(545, 433)"></a>
</li>

And here is my javascript:

function windowpop(url, width, height) {
    var leftPosition, topPosition;
    //Allow for borders.
    leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
    //Allow for title and status bars.
    topPosition = (window.screen.height / 2) - ((height / 2) + 50);
    //Open the window.
    window.open(url, "Window2", "status=no,height=" + height + ",width=" + width + ",resizable=yes,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
}

This seems to return a 404 error when tested. What am i doing wrong?

Thanks heaps.

like image 768
user2105885 Avatar asked Apr 24 '13 03:04

user2105885


1 Answers

function windowpop(url, width, height) The function requires a URL to be returned to it.

onclick="return windowpop(545, 433)" You're only returning the width and height.

Try returning the URL using this.href:

onclick="return windowpop(this.href, 545, 433)"
<script>
function windowpop(url, width, height) {
    var left = (screen.width / 2) - (width / 2);
    var top = (screen.height / 2) - (height / 2);
    window.open(url, "", "menubar=no,toolbar=no,status=no,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left);
}
</script>
like image 74
Mal Avatar answered Oct 04 '22 05:10

Mal