PDA

View Full Version : pop-up window that works for old browsers


baardvidar
09-26-2002, 08:31 PM
I thought this would be easy, even for me, but I guess that goes to show what a real beginner I am. What I need for my site is a link that pop-ups a window for those that has js enabled browsers and opens a standard window using the HTML "_blank" feature for those that have old browsers. I got this script at javascriptkit.com:

<script>

function openpopup(){
var popurl="thankyou.htm"
winpops=window.open(popurl,"","width=400,height=338,")
}

</script>

<a href="javascript:openpopup()">Click here to open window</a>


I thought my solution was as simple as modifying the anchor tag like this:

<a href="thankyou.htm" target="_blank" onclick="javascript:openpopup()">

I thought the javascript action would override the link action, but it don't, so I now have 2 pop-ups. Anyone know how to fix this? If there is no way to fix this, is there a way to open a new window with plain HTML, and have js resize it, and remove the menu and scroller?


Thanks,
Amateur Baard

baardvidar
09-26-2002, 08:34 PM
Hey, it wasn't my idea to put smilies in the script. The code is supposed to be:'

<a href="default.htm" target="_blank" onclick="javascript:openpopup()">

adios
09-26-2002, 08:42 PM
What's wrong with 2 pop-ups? (can't have too many pop-ups).

OK:

<a href="default.htm" target="_blank" onclick="return openpopup()">

function openpopup(){
var popurl="thankyou.htm";
winpops=window.open(popurl,"","width=400,height=338");
return false;
}

JSB
09-26-2002, 08:50 PM
I'm fairly certain (but then I am sometimes incorrect) that you would use the tags <noscript>alternative html/href here to open a normal window with target="_new"</noscript>

If the browser does not have javascript enabled, no matter what you do (using javascript), javascript on the client side will not do anything for you.

baardvidar
09-26-2002, 08:53 PM
Heaps of thanks! I'm not really sure what you did, but it worked and so I'm happy!! Ignorance is bliss!

Baard:D

JSB
09-26-2002, 09:07 PM
Cool.

;)

baardvidar
09-26-2002, 09:36 PM
Not to discredit you JSB, your solution would probably have worked, but the thanks went to Adios for the corrected javascript. By coincidence, you posted your reply while I replied to Adios. Though, reviewing what you have suggested, JSB, that would be another simple remedy.

Thanks both!

JSB
09-26-2002, 10:33 PM
:o

adios
09-27-2002, 02:37 AM
Props to baardvidar for being thoughtful enough to be specific in directing his response (means something out here).

btw - instead of simply running your 'openpopup()' function, you're returning something (a false value) as well; it's then passed along the line (onclick="return openpopup()) where the false return can cancel the default outcome of the click event - the loading of the href. For <a onclick="...."> the bit in red is always a function (or a function pointer), slipped in there by the browser, so a return inside it is necessary to move the value to where it can kill the linking action. No JS - no killing.

JSB: no such (special target) animal as "_new" (unless that's a custom name). Using <noscript> is exactly what the above 'redundancy' is designed to make unnecessary.

JSB
09-27-2002, 03:47 PM
Oh G.
I even took the time to look up the special emoticon that is supposed to indicate embarrassment. I hope you're not picking on me, too.

You went to my sight to check out my non-javascript-programmer kinda of javascript? You really want to make me look bad.

The return infront of the popwindow function is something that I found on irt.org (I think that's where it was). The function doesn't just open a window, whenever the click event on that link is clicked, the function is supposed to check if the popup is already open and sitting on the user's task bar. I wanted to be considerate and not have a million windows open up but the same one to be reused in most cases.

The target="_new" is something that I've been using since '98 when I found was that users behind a fire wall didn't get a new window using the target _blank; they got nothing. But someone told me that although it's not a real target option that _new works for everyone.

Sorry you mistook my choice of emoticons as something other than embarrassment.

BTW. Thanks for pointing out those links that are not working.
I changed that function (as well as the name) but forgot to make the changes on the index. D'oh!

There are a lot of pages on that site. I thought that I had got them all. Damn.