Forum Moderators: open

Message Too Old, No Replies

Disabling 'a href'

for those with javascript ENABLED

         

nigassma

5:40 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



RocknBill responded to a post a while back that asked for a simple popup window that's size could be controlled:

---js---
<script type="text/javascript">
function newWindow(url) {
var day= new Date();
var id = day.getTime();
var win = open(url,id,'width=560,height=650,scrollbars,resizable');
}
</script>

---HTML---
<a href="rockin/bill.htm" target="_blank" onClick="newWindow('rockin/bill.htm');" return false;>Rockin Bill,</a> javascript<br />

------------------------------

My question is: What is the best way to let the javascript enabled visitors see the page in the popup window without it also opening in a new target page that is meant for the non-javascript users.

Right now it opens in two places for js-enabled visitors and one for the js-disabled visitors.

It's the same page in both instances.

Is there also a way to include the "close" button only in the javascript popup window?

---javascript---
<button onclick="window.close()" value="Close Window" />

garann

10:20 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



The code you have there should prevent a second window from opening except that you seem to have some code outside the quotes it needs to be in:
<a href="rockin/bill.htm" target="_blank" onClick="newWindow('rockin/bill.htm');[b]" return false;[/b]>Rockin Bill,</a> javascript<br />

Moving 'return false;' inside the double quotes should fix you up.

As for your button, my first thought would be to have some Javascript at the end of the page check whether the 'opener' object was null and, if so, set the button's style to

display:none
. There's probably something more elegant, but I think that'll work.

nigassma

11:11 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



This is what I'm thinking but don't know if it's right.

I want to insert this:

<button onclick="window.close()" value="Close Window" />Close Window

onto a htm page. I only want it to appear on the page that opens with javascript. When a browser access' it through 'a href' then I don't want it to be there.

Would writing an if/else statement hide the close button from non-javascript enabled browsers? This is probably way off from where it needs to be, but this is what may be needed on each htm page.

Any ideas?

if (javascript enabled) {
<button onclick="window.close()" value="Close Window" />Close Window
}
else (no javascript){
null;
}

garann

11:21 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



Oh, good call, I guess it really is as simple as only displaying it when Javascript is enabled. You might just use document.write. In this special circumstance, it actually makes sense.

<script type="text/javascript">
document.write("<button onclick='window.close()' value='Close Window' />")
</script>

nigassma

11:32 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



F-in awesome! Sweet response time and awesome response! Best part about it was that's exactly what I was thinking!

:)

Thanks bud!

garann

11:47 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



Cool, glad you got it worked out. :)