Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form button, target new window, beat google toolbar 4

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
hi,

How can you make a normal form button, that onclick targets a new window, that beats google toolbar pop-up blocker and is still X/HTML 1.1 strict compliant?

I did it as a form and had a submit button and used JS to attached the target attribute to enable X/HTML validation, but google sees a form being submitted to a new window as a popup.

if it sees a submit button to submit a form that must be clicked as a pop-up , why doesn't it just go the whole hog and deactivate every anchor while it's at it!


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I know, the problem is I have no control over Joe Public's PC, and if it gets blocked by google it might get blocked by yahoo, zone alarm, and many, many more I just can't test for.

I'm not down with having a warning, it's getting rediculous these days you need to make your home page...

To use our site you will need to comply with the following...
1. Enable JS.
2. Disable Pop-up blocker
3. Turn off FireWall
4. Allow Active-X
5. Accept Java VM
6. Allow Flash Player.
7. Use a CSS Capable browser
8. Phone your mum and ask permission
9. Run round the room with your pants on your head, 5 times.
10. Say 3 hell mary's and flog yourself for an hour.

I have visited the odd site that has a list of rubbish needed to view their site, personally I said to myself 'I aint reading, let alone complying with that stuff, i'm off'

and left the site and I beleive most people would leave a site with a huge list of things required to be done just to view their website.

I think i'll change tactics and use some form of scrollto to get to where I want instead of anchor.





"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I know this is more a JS final solution, but I thought I'd post it anyhow, as it is a fix to the problem.

Code:
    var e = document.getElementById('q3');                               		      
    window.scrollTo(e.offsetLeft,e.offsetTop);

does the job nicely :)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
The trick is to build things that either:

1. Don't require the presence of a particular function or piece of software
2. Don't require the absence of a particular function or piece of software

I'd say where you are going wrong is requiring the need to allow a popup. If you removed that need you would remove your problem. Like you said, you can't control Joe Public's PC. So why even try?


<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
I'd say where you are going wrong is requiring the need to allow a popup
Come on foamy, I have greater respect for you than that, you know as well as I that what I am doing is not a pop up! that's insulting [machinegun]

I simply want an anchor to open a PDF in a new browser window/tab since when has
Code:
<a href="myurl" target="_blank">click here</a>
ever constituted as a popup.

The requesite of the design was that the IDD & Privacy PDF's will open a new browser window (if Adobe Reader is configured to 'Open in Browser') or open directly into Acrobat (which would be the preferred method).

These documents are regulatory documents, which need to be treated separately from content on a web page, they need to be saved, printed, kept!, as they form part of a regulated activity controlled by the FSA.

I have done my best to steer clear of any other X/HTML 1.1 rule breakers, such as targeting outside the current window. Breaking the back button etc...

I have weened myself off of tables completely , use CSS where ever possible to control layout / design and a smattering of JS where required.

So it aint that bad really, is it, so no need to call my code a pop-up - lol
[roll1]



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
since when has <a href="myurl" target="_blank">click here</a> ever constituted as a popup.
Looks exactly like a pop up to me. As a user of your site you are trying to force me to open the file in a new tab/window. What happens if I want to open it in the same window? Why can't I have the choice?

I know what you are getting at when you say it's not a pop-up; you mean it's not an annoying pop-up that I didn't want advertising some rubbish that I will never want or use! However, it's still a pop-up and you are still trying to force something upon the user. By depreciating the target attribute from the DOCTYPE you've chosen, I'm sure W3 want you to give the user the choice so why not just go with the standards and let your user's decide what they want to do?


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
OK, popup was the wrong word :)

Force of habit.

And if you are opening a new window to follow FSA guidelines then I guess there isn't much you can do about it.

I still get the feeling that the cause of the problem is something to do with the file type though.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
filetype? it's a PDF! I bet using document.location.href within an onclick , which is triggered via an anchor which is targeting a new window would trigger a block in google no matter how you tried it.

ca8msm - I appreciate what your saying but I also look at it from a user point of view, as me being a user.

How many times do you click a link and when you finished reading the page you click the [x] instead of back and close the window.

I do it all the time, and I watch many users do it also. If I go to a site that says please click here to view our XYZ policy, I expect it to open in a new window, and so do many, especially if it is a PDF.

I find it annoying when it opens in the website window I was on. Now ok, I know you can hold CTRL and click a link to open in a new window, but be honest how many box standard users do.

i have trouble getting our staff to remember F5 = refresh, CTRL+C = Copy , CTRL-V = paste , CTRL-A = select all etc. etc.. you get the picture.

Half don't know what ALT-TAB switching is, let alone find the windows key, and boy if their keyboard is set USA , they have no hope in knowing the @ is the double quotes and vice versa! - let alone how to change it!

Anyhow, I always thought and believe is still true, the definition of a pop-up is a window that opens by itself not attached to a user onclick event.

I can even accept onclick="window.open()" (with gritted teeth!) being blocked, but <a href="" target=""> , never!

You also need to appreciate that if I went to a site, was halfway through some questions, needed to view and print a legal document, it opened in the same window and I , yet again , like the idiot I am, click the little red cross, which is always begging and pleading to be clicked.

Bang, website shut, document gone, gotta go back to the site and answer the same questions again, view the document again, and if i'm lucky remember to click back this time instead of close!!!

I know what I'd say "aghh forget it , what was that other site called dear?"

Come on you know you would [rofl2]



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I see what you are saying and I imagine some users do have that problem. However, they are not in the business of trying to follow standards whereas we (being professionals in this field), I think should be.

Imagine (in an ideal world) if the option of opening a new window or tab from a link had never existed. We would all learn how to use the back button, the close button etc properly. Now, this ideal world will never exist and we can't think that it ever will. However, isn't this why standards exist. If we all try to conform to those standards them everyone will know what to expect from our websites. Clicking a link on every site will do exactly the same thing so the user's will learn how to use the tools given to them.

It's like all the different browsers implementing HTML in a different way. Surely if they all did the same we would all be better off? Why is this different when using a website? I don't think it is and that's why I think the user should be given the chance to use standarised websites.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
very well put, and I do agree, we all probably do click the [x] instead of using the back button from habit, and perhaps this habit needs breaking.

I even fail to use tabbed browsing properly and still prefer to open multiple windows rather than tabs.

I also when clicking a link to another site prefer a new window, I can handle 20 windows in the task bar, that's why it's a multi-tasking 'Windows' orientated OS isn't it?

This I know is applying my preference onto others, rather than just appying the rules and let people find out the hard way and break those bad habbits.

However i do beleive that a website has the right to control the way it works to a degree, not just from a design point but functionality also.

balancing the users preferences and website functionality and design is a very trick thing to get 100% right.

As you say there is no 'ideal world', 'ideal user' and so thus there is no 'ideal wesbite' ;-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Yep 'X' closes the window so how would it follow that if I close the window I can continue where I left off? It's illogical and only necessary IF you open things in new windows to start with.
That said, I can see why someone may want to open privacy statements etc in a new window.

Anyway... I mentioned the file type because its a PDF. Your browser (IE?) may be trying to do something with that (open Acrobat Reader within IE) which, when combined with you trying to open a new window, is causing the popup blocker to interfere.

Just to clarify, and so I can test something, which actual link/button on your page is it you are referring to?

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
I do have 'currently' my Adobe to 'Open in Browser' , one of our partner companies were having major issues with this set and I was testing. normally I would prefer a PDF to open in Adobe Reader NOT the browser.

Ok the link in question ... it is the 'view KeyFacts', it is an image wrapped in an anchor with the img having onclick="hide_idd();" and the anchor having href="idd.pdf" and onclick="this.target='_blank';"

The hide_idd JS is as follows (what causes a problem)...
Code:
// Hide IDD //
function hide_idd(){
    document.getElementById('idd').style.display='none';
    document.getElementById('q3').style.display='block';
    document.location.href='#q3';
}

and the code that works fine...
Code:
// Hide IDD //
function hide_idd(){
    document.getElementById('idd').style.display='none';
    document.getElementById('idd_wrapper').style.display='none';    
    document.getElementById('q3').style.display='block';

    var e = document.getElementById('q3');                               		      
    window.scrollTo(e.offsetLeft,e.offsetTop);

}

so my conclusion is you cannot do this <a href="my.pdf" onclick="this.target='_blank'; document.location.href='#q3';">Click Here</a>

here is a working example... , google blocks the pdf opening and only jumps to #q3

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
OK, so just to humour me. Do you see the same behaviour if the button isn't opening a PDF but just opening a regular HTML page?

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
ok just to humour you I changed it to my.html, but I didn't expect it to make a difference as the my.pdf nor my.html actually exist so it should just be a standard 404 error page ;-)

No change, google blocks it!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
OK, at least it rules the PDF factor out.

I can't test this theory but it might be worth considering:

What happens if you add a return false; to the event handler? It could be that the popup blocker is looking for multiple actions from a single click and thinking it's bad behaviour. This would match the pattern of a nasty popup i.e. go to a new page AND open another window.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
nm, you aren't doing what I thought you were doing

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Using your test.html file and installing Google toolbar on my old IE6 equipped laptop I could reproduce your problem.

However, changing the onclick event handler to

Code:
onclick="window.open(this.href);document.location.href='#q3';return false;"

Got it to work.
The main window jumps to the anchor and a new window is opened with the my.html loaded. Not a peep from Google Toolbar Popup blocker.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
if I could give you another star i would :)

So why does the return false make such a difference? Is the onclick event waiting for a return from the executing script? doesn't it auto return false? (null) if nothing is returned?

and isn't this now well and truly a JavaScript questions?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
The return false tells the browser that the onclick handler wasn't successful so it stops processing any other actions. i.e. it does not process the 'normal' link behaviour. I think that's a fairly accurate summation. I'm not really au fait with the technicalities of Javascript and browser processing.

My guess is that the popup blocker, looking for suspicious behaviour, thinks that because the 'normal' link is followed the additional window opening is a bit suspect (or vice versa). Think about it. That's how those annoying popups and popunders work.

By adding the return false the onclick event stops any further http request from happening. 1 click, 1 action.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Unfortunately it still doesn't work if using an anchor :-(

Your using onclick & window.open , window.open within an onclick it's deactivated by Norton Internet Securities, so that method is no good.

If I put return false on the end of the test.html code i knocked up, all it does is jump to #q3 , no popup and no blocked popup.

It as you say seems to kill the onclick event, but it also kills the <a href> natural behaviour to open the link, so one must assume that <a> has some form of built in onclick and the retuen false is killing that also.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Yes the return false stops the regular link behaviour.
But you had a document.location.href in the onclick event which did the jumping.

I'm not convinced that onclick="this.target='_blank'" is going to work anyway. Could it be that your onclick event is erroring at that point and so not executing the rest of the code in the event?

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top