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.
 
hello monksnake,

here is the code
Code:
<form id="idd_form" action="idd.pdf" method="get" onsubmit="return sub_idd();"><table><tr><td class="title" valign="top"><div style="float:left;">KeyFacts about our service</div><div style="float:right;">[<a href="javascript:close_idd();" title="Close">X</a>]</div></td></tr><tr><td align="center">Before proceeding to the online quotation system, please ensure you read the following KeyFacts document describing the service we provide.<br /><br />We recommend you print this document and keep it in a safe place.<br /><br />Click the 'View KeyFacts' button to continue to the document.<br /><br />Once finished, simply close the document window to continue.<br /><br /><input type="submit" style="cursor:pointer;" value="View KeyFacts" onclick="hide_idd();" /><br /><br />Before completing the application form,<br /> we adivse you read our <a href="privacy.pdf" onclick="this.target='_blank';" title="View our Privay Policy">Privacy Policy</a>.</td></tr></table></form>

a simple action = pdf and submit button onclick attaches the target attribute, but google won't play ball


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Try this:
Code:
<a href="privacy.pdf" target="_blank" onclick="window.open('privacy.pdf')" title="View our Privay Policy">Privacy Policy</a>

You may be able to play around with this code to make it cleaner, but I got this from another page, and supposedly it bypasses Google popup blocker.

It is still XHTML1.1 compliant.

[monkey][snake] <.
 
target="_blank" , you cannot use target and be X/HTML 1.1 strict compliant.

also the privacy link works fine, it's the idd.pdf form submission that is being blocked.

I might just create an image for the button and make it an anchor.

between pop-up blockers, non-JS , firewalls and vista UAC, my PC is starting to become more usefull as a door stop or paper weight than a computer!!!!!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Well, I was going to try to test your situation, but our good-ol firewall kept me from d/ling google toolbar. (Non-Standard). Also, apologies on the XHTML 1.1 with target, I swore it was compliant, but I was wrong.

[monkey][snake] <.
 
This should work and be standards compliant. Plus it 'degrades gracefully'
Code:
<a href="privacy.pdf" onclick="window.open(this.href);return false;">Download PDF</a>



<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
hey Foamy,

I take it from your suggestion it just isn't possible with a standard form button.

Also window.open is blocked by pop-up blockers aren't they?

Especially programs like Norton, Norton makes the window.open command defunct.

seems a bit odd that a submit button can't be used , still don't understand how on earth it thinks it is a pop.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Hi

1DMF said:
Also window.open is blocked by pop-up blockers aren't they?
Not always. Good pop-up blockers have option to block everything or block only unwanted pop-ups. In Foamcow's code the [tt]window.open()[/tt] is executed only when the used clicks the links. Usually that is considered wanted pop-up and is not blocked.

But of course, third party pop-up blockers like the mentioned Norton ( as far as I know ) tends to block everything by altering the HTML code.

Personally I would ignore this later case.

Feherke.
 
yep that's been a thorn in my side for years, which is why I recommend people steer clear of Norton.

It blocks all window.open commands regardless, as you say by altering the HTML code. Nightmare! it also affects the onclick attribute not just for window.open, i've also had problems with document.location.href and Norton.

But this is why I was suprised to find Google Toolbar blocking a submit button of a form just because it targeted a new browser window.

it is on a button that the user must click, so not a pop-up in my definition book, but was blocked all the same.

I just used a href and an img with mouseover/out effects to achieve the desired result, but is a real pain as you would have thought a simple form button would have done the job.

Now I have to create buttons and rollover effects instead of using the built in DOM tags, what is HTML coming to when a simple submit button won't work! - lol

[bugeyed]




"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
You could try targeting the link/button from outside the HTML.

Code:
<a rel="extLink" href="privacy.pdf">Privacy</a>


Then using external javascript

Code:
function externalLinks() {
	if(!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName('a');
	for (var i=0; i<links.length; i++) {
		var thislink = links[i];
		if (thislink.getAttribute('rel')=='extLink'){
			thislink.setAttribute('title','Opens in a new window');
			thislink.onclick = function(){
				window.open(this.href);
				return false;
			}
		}
	}	
}

Dunno if it will definitely work as it may be treated just the same as an inline onClick event. But you never know, it might be worth a try.

Either way, this is now straying in the Javascript forum.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Forgot to say, you will need to call that function once the page has loaded in whatever way suits your needs.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Thanks Foamy, I did it more or less like that, i simply added onclick="this.target='_blank'" to the anchor, it does the job of being a standard anchor and beating popup blockers and remains X/HTML 1.1 strict valid, if only in name and not function ;-)

I guess however you fool the code validator and use JS to attached attributes to tags, it's still breaking the rule, so maybe I shouldn't be writing to 1.1 standards doc type.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Did my method work?
I don't have IE or Google toolbar to test it, but it would be interesting to know if it got around the blocker.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
No, in answer to your question Foamy!

I do not understand why google toolbar is behaving in this manner. I've even put the target tag on the anchor and google still sees it as a popup.

I can't think what else to do, if I put your code in a page on its own then it works.

However if applied to my image within the hidden div, when the div is shown and the img button clicked , using your code opens the PDF in the same window not a new window.

And as i said, if i just simply use the target attribute on the anchor google toolbar blocks the new window.

Does anyone know why google is doing this, is it something to do with layer (z-index) I can't think what else could be causing this, a standard anchor wrapped around an image with a target and it's being blocked.

any ideas peeps?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Are you sure you don't have some javascript error occuring?
How about with other file types than PDF?

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
nope , not that I can see, try yourself!


it's not an error problem, it's a popup problem and I can't understand why.

what on earth is making <a href="#" target="_blank"><img></a> a popup, it's a standard anchor targeting a new window, this has never been a pop-up so what on earth is Google doing?

i've validated the code and don't get any errors, i'm stumped!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Hi

1DMF, no idea if this time is intended or not. There is still [tt]z-index[/tt] interference with the layers.
[ol]
[li]Do you have a pre-exisiting medical condition? - Click [COLOR=white navy] No [/color][/li]
[li]Do you want to talk to one of our professional advisers? - Click [COLOR=white navy] No [/color][/li]
[li]KeyFacts about our service - Click [highlight #265290][white][[/white][silver]X[/silver][white]][/white][/highlight][/li]
[/ol]
After that the idd_wrapper [tt]div[/tt] will cover the links again.

Feherke.
 
well done feherke, spotted a bug i'd missed, the [x] failed to hide the wrapper div! many thanks.


I've also worked out what is causing my popup problems, I don't quite understand why, but at least I found the culprit.

When you click on 'View KeyFacts' it opens the PDF in a new window, hides the KeyFact (idd) div and jumps to the 3rd question.

eg...
Code:
// Hide IDD Popup //
function hide_idd(){
    document.getElementById('idd').style.display='none';
    document.getElementById('idd_wrapper').style.display='none';    
    document.getElementById('q3').style.display='block';
    [b]document.location.href='#q3';[/b]
}

this executes via onlick on the IMG. the problem was the bit I've highlighted.

For some reason, trying to open an anchor via a click to a new window with JS and trying to jump to a location on the current page causes a conflict and Google kills the opening window.

If i remove the document.location.href='#q3'; the code works fine, so does any know why it is doing this and how I may be able to stop it? and enable the auto jump to the #q3 location on the current page?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Call me nuts, but if Google toolbar keeps giving you problems, just uninstall it, and put a note on your page stating the toolbar must be disabled to use your page. Here where I work, Google toolbar is a nonstandard 3rd party program, it won't even let me install it.

[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top