Page 1 of 1

create an javascript alert before linking to a new php page

Posted: Wed Sep 12, 2012 5:46 am
by jonnyfortis
I have a image button that links through to a new page but i need an alert to popup before the page is viewed but i am getting an error i have so far

<script type="text/javascript">
<!--
function navConfirm(loc) {
if (confirm('your have 72 to ours to query the document')) {
window.location.href = loc;
}
return false; // cancel the click event always
}
//-->
</script>

<a href="../admin/docs/<?php echo $row_Recordset1['Inventory']; ?>" onclick="return navConfirm(this.ref);" target="_new"><img src="../images/smalldownload.png" width="35" height="35" alt="download" /></a>

but when i run it i get the following error page

The requested file http://www.website.com/beta/signup-login/undefined does not exist on the web server, it may be a misspelling or perhaps it was removed in a website restructure.


thanks in advance

Re: create an javascript alert before linking to a new php p

Posted: Wed Sep 12, 2012 5:51 am
by pbs
Check the onclick="return navConfirm(this.ref);"
Use "this.href"

Re: create an javascript alert before linking to a new php p

Posted: Wed Sep 12, 2012 6:02 am
by jonnyfortis
I have tried it with using just a text link to a website

<a href="http://www.thiswebpage.com" onclick="return navConfirm(this.href);">This Webpage</a>

and that works fine. IM not sure what you mean Use "this.href"

thanks

Re: create an javascript alert before linking to a new php p

Posted: Wed Sep 12, 2012 6:22 am
by pbs
You missed "h", while passing parameter in navConfirm() function, you have passed "this.ref", so I asked you to write it correctly

Checked the underline part of your code

<a href="../admin/docs/<?php echo $row_Recordset1['Inventory']; ?>" onclick="return navConfirm(this.ref);" target="_new"><img src="../images/smalldownload.png" width="35" height="35" alt="download" /></a>

You may have got what I mean to say...

Re: create an javascript alert before linking to a new php p

Posted: Wed Sep 12, 2012 6:32 am
by jonnyfortis
Oh yes, thanks for that, little slow today

thanks again

Re: create an javascript alert before linking to a new php p

Posted: Wed Sep 12, 2012 6:33 am
by pbs
Is your issue resolved?

Re: create an javascript alert before linking to a new php p

Posted: Wed Sep 12, 2012 7:11 am
by jonnyfortis
yes except i woant it to appear in a new window

this is what i have

<a href="../hostadmin/docs/<?php echo $row_Recordset1['Inventory']; ?>" onclick="return navConfirm(this.href);" target="_new"><img src="../images/smalldownload.png" width="35" height="35" alt="download" />


thanks

Re: create an javascript alert before linking to a new php p

Posted: Wed Sep 12, 2012 7:22 am
by pbs
Use target="_blank" instead of target="_new" in anchor tag

Re: create an javascript alert before linking to a new php p

Posted: Wed Sep 12, 2012 7:27 am
by pbs
I think it will not work as you are using javascript function to open the links. You need to use javascript window.open() function to open url in new window.

Re: create an javascript alert before linking to a new php p

Posted: Wed Sep 12, 2012 8:11 am
by jonnyfortis
ok will leave at as it is thanks for your help