create an javascript alert before linking to a new php page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

create an javascript alert before linking to a new php page

Post 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
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

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

Post by pbs »

Check the onclick="return navConfirm(this.ref);"
Use "this.href"
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

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

Post 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
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

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

Post 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...
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

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

Post by jonnyfortis »

Oh yes, thanks for that, little slow today

thanks again
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

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

Post by pbs »

Is your issue resolved?
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

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

Post 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
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

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

Post by pbs »

Use target="_blank" instead of target="_new" in anchor tag
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

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

Post 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.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

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

Post by jonnyfortis »

ok will leave at as it is thanks for your help
Post Reply