PDA

View Full Version : Javascript confirmation box


Falcon Capt
07-18-2010, 01:38 PM
I am trying to use the following script to create a Confirmation Popup box for my "Mark All Forums Read" link, but it isn't working.

In my Navbar template I placed the following at the top:

<vb:literal>
<script>
<!--
function markAsRead()
{
var markRead= confirm("Do you really want to mark all forums as read?");
if (markRead== true)
{ window.location="forumdisplay.php?{vb:raw session.sessionurl}do=markread&amp;markreadhash={vb:ra w bbuserinfo.securitytoken}";
}
else
{
}
}
//-->

</script>
</vb:literal>


I changed the link for "Mark All Forums Read" to:

<a href="javascript:markAsRead();"><b><font color=red>{vb:rawphrase mark_forums_read}</font></b></a>




I end up getting the following error in my browser when trying to follow the link:

Invalid Forum specified. If you followed a valid link, please notify the administrator


I noticed when the page changes, the URL shows up as: http://www.mysite.com/forumdisplay.php?{vb:raw session.sessionurl}do=markread&markreadhash={vb:raw bbuserinfo.securitytoken}

It looks like the hash and security tokens are not being passed in the Java Script as they were in vB3.




I was able to use the following in vB3.8.5 and it works fine, but it isn't working in vB4.x:

<script>
<!--
function markAsRead()
{
var markRead= confirm("Do you really want to mark all forums as read?");
if (markRead== true)
{ window.location="forumdisplay.php?$session[sessionurl]do=markread&amp;markreadhash=$bbuserinfo[securitytoken]";
}
else
{
}
}
//-->

</script>

<a href="javascript:markAsRead();">$vbphrase[mark_forums_read]</a>


Any help would be greatly appreciated!



.

Falcon Capt
07-19-2010, 07:23 PM
* Bump *

Boofo
07-19-2010, 08:17 PM
Try adding the javascript to the headinclude or header template.

Guest190829
07-19-2010, 08:36 PM
The problem is you wrapped the javascript around <vb: literal> tags, which you should do, but that means none of the {vb: raw } tags are being parsed in the script.

Maybe try passing this data through the function?


<a href="javascript:markAsRead({vb:raw session.sessionurl},{vb:raw bbuserinfo.securitytoken );">{vb:rawphrase mark_forums_read}</a>
<vb:literal>
<script>
<!--
function markAsRead(session, markreadhash)
{
var markRead= confirm("Do you really want to mark all forums as read?");
if (markRead== true)
{ window.location="forumdisplay.php?" + session + "do=markread&amp;markreadhash=" + markreadhash;
}
else
{
}
}
//-->

</script>
</vb:literal>

Falcon Capt
07-19-2010, 08:51 PM
Try adding the javascript to the headinclude or header template.Tried both, no change.

The problem is you wrapped the javascript around <vb: literal> tags, which you should do, but that means none of the {vb: raw } tags are being parsed in the script.

Maybe try passing this data through the function?


<a href="javascript:markAsRead({vb:raw session.sessionurl},{vb:raw bbuserinfo.securitytoken});">{vb:rawphrase mark_forums_read}</a>
<vb:literal>
<script>
<!--
function markAsRead(session, markreadhash)
{
var markRead= confirm("Do you really want to mark all forums as read?");
if (markRead== true)
{ window.location="forumdisplay.php?" + session + "do=markread&amp;markreadhash=" + markreadhash;
}
else
{
}
}
//-->

</script>
</vb:literal>I tried the above but get a "Syntax Error".

I think we are getting closer as it makes sense that the vb:literal tags are causing the noparse.

Guest190829
07-19-2010, 08:54 PM
What's the syntax error? I see already that I missed a ")"

so,

<a href="javascript:markAsRead({vb:raw session.sessionurl},{vb:raw bbuserinfo.securitytoken});">{vb:rawphrase mark_forums_read}</a>

might fix it.

Falcon Capt
07-19-2010, 09:07 PM
What's the syntax error? I see already that I missed a ")"

so,

<a href="javascript:markAsRead({vb:raw session.sessionurl},{vb:raw bbuserinfo.securitytoken});">{vb:rawphrase mark_forums_read}</a>

might fix it.Still no-go.

It doesn't tell me what the Syntax Error is.

When I hover over the link, it shows:

javascript:markAsRead(,1279577127-xxxxxxxxxxxxxxxxxxx)

It appears there might be a hash missing. Also, when I click on the Mark All Read button, I don't get the confirmation popup either.

Guest190829
07-19-2010, 09:26 PM
Try:


<a href="javascript:markAsRead('{vb:raw session.sessionurl}','{vb:raw bbuserinfo.securitytoken}');">{vb:rawphrase mark_forums_read}</a>

Falcon Capt
07-19-2010, 09:36 PM
Try:


<a href="javascript:markAsRead('{vb:raw session.sessionurl}','{vb:raw bbuserinfo.securitytoken}');">{vb:rawphrase mark_forums_read}</a>


EXCELLENT!!!

That appears to have done the trick!

THANK YOU for your help!!! :up::up::up::up::up::up::up::):):):):)

Boofo
07-19-2010, 09:43 PM
Where did you end up putting the js code?

Falcon Capt
07-19-2010, 09:55 PM
Where did you end up putting the js code?

At the very top of the navbar template.

Guest190829
07-19-2010, 09:59 PM
No problem. :)

And Boofo is right, javascript should go in the headinclude template.

Falcon Capt
07-19-2010, 10:08 PM
No problem. :)

And Boofo is right, javascript should go in the headinclude template.Ok, moved it to the header_includes template.

One other problem I am having with this script. Occasionally in certain browsers, I get a "Your Submission could not be processed due to an invalid security token" error when trying to Mark All Read. Doesn't happen in IE8, but happens on the browser on my Droid (Safari derivative I believe).

Any thoughts?

Guest190829
07-19-2010, 10:16 PM
This occurred with the new version? Or has been happening?

Falcon Capt
07-20-2010, 07:33 PM
This occurred with the new version? Or has been happening?Actually happened in 3.8.5 as well. Only seems to be certain browsers (mostly mobile browsers). Almost appears as though the browser isn't passing the security hash through the script (it is a java enabled browser).

Boofo
07-20-2010, 07:43 PM
Is there anyway to check if the browser handles js and use the regular link for those occasions that it doesn't?

Falcon Capt
07-20-2010, 07:55 PM
Is there anyway to check if the browser handles js and use the regular link for those occasions that it doesn't?The browser does handle js. If I remove the following code from FORUMDISPLAY.PHP it works properly:

// Prevent CSRF. See #32785
$vbulletin->input->clean_array_gpc('r', array(
'markreadhash' => TYPE_STR,
));
if (!verify_security_token($vbulletin->GPC['markreadhash'], $vbulletin->userinfo['securitytoken_raw']))
{
eval(standard_error(fetch_error('security_token_in valid', $vbulletin->options['contactuslink'])));
}

So it is something with the CSRF protection (this issues started with vB 3.8.5 when they put CSFR protection on the Mark All Read function.)

Guest190829
07-20-2010, 08:06 PM
Can you check the URL upon redirect? Is there a hash in the query string?

Falcon Capt
07-20-2010, 08:43 PM
Can you check the URL upon redirect? Is there a hash in the query string?I really can't tell as there is no way to see the full link during the redirect on the mobile browser.

omerfarukak
08-28-2011, 08:33 AM
I'm trying to use this method but when i add this function and hit the save button, it says

Fatal error: Maximum function nesting level of '100' reached, aborting! in /var/www/includes/vb_template.php on line 51

how can i resolve this problem?

--------------- Added 1314536746 at 1314536746 ---------------

Finally, i can include this function from external file...

But now it's not working with vb4.1.5

I've add <script type="text/javascript" src="markread.js"></script> this to headerinclude and it's contains function markAsRead(session, markreadhash)
{
var markRead = confirm("Butun mesajlar okundu kabul edilecek. Emin misiniz?");
if (markRead == true)
{ window.location="forumdisplay.php?" + session + "do=markread&amp;markreadhash=" + markreadhash;
}
else
{
}
}

then i'have change mark as read link with this <a href="javascript:markAsRead({vb:raw session.sessionurl},{vb:raw bbuserinfo.securitytoken});">{vb:rawphrase mark_forums_read}</a>

This doesn't work... What can we do?