vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Javascript confirmation box (https://vborg.vbsupport.ru/showthread.php?t=246826)

Falcon Capt 07-18-2010 12:38 PM

Javascript confirmation box
 
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:

Code:

<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:raw bbuserinfo.securitytoken}";
 }
 else
 {   
  }
}
//-->

</script>
</vb:literal>


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

Code:

<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:

Quote:

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:ra w 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:

Code:

<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>

Code:

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

Any help would be greatly appreciated!



.

Falcon Capt 07-19-2010 06:23 PM

* Bump *

Boofo 07-19-2010 07:17 PM

Try adding the javascript to the headinclude or header template.

Guest190829 07-19-2010 07: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?

Code:

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

<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 07:51 PM

Quote:

Originally Posted by Boofo (Post 2071709)
Try adding the javascript to the headinclude or header template.

Tried both, no change.

Quote:

Originally Posted by Danny.VBT (Post 2071715)
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?

Code:

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

<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 07:54 PM

What's the syntax error? I see already that I missed a ")"

so,

Code:

<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 08:07 PM

Quote:

Originally Posted by Danny.VBT (Post 2071725)
What's the syntax error? I see already that I missed a ")"

so,

Code:

<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 08:26 PM

Try:

Code:

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

Falcon Capt 07-19-2010 08:36 PM

Quote:

Originally Posted by Danny.VBT (Post 2071736)
Try:

Code:

<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 08:43 PM

Where did you end up putting the js code?

Falcon Capt 07-19-2010 08:55 PM

Quote:

Originally Posted by Boofo (Post 2071741)
Where did you end up putting the js code?

At the very top of the navbar template.

Guest190829 07-19-2010 08:59 PM

No problem. :)

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

Falcon Capt 07-19-2010 09:08 PM

Quote:

Originally Posted by Danny.VBT (Post 2071745)
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 09:16 PM

This occurred with the new version? Or has been happening?

Falcon Capt 07-20-2010 06:33 PM

Quote:

Originally Posted by Danny.VBT (Post 2071750)
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 06: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 06:55 PM

Quote:

Originally Posted by Boofo (Post 2072147)
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:

Code:

// 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_invalid', $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 07:06 PM

Can you check the URL upon redirect? Is there a hash in the query string?

Falcon Capt 07-20-2010 07:43 PM

Quote:

Originally Posted by Danny.VBT (Post 2072156)
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 07: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 [DATE]1314536746[/DATE] at [TIME]1314536746[/TIME] ---------------

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

But now it's not working with vb4.1.5

I've add
Code:

<script type="text/javascript" src="markread.js"></script>
this to headerinclude and it's contains
Code:

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
Code:

<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?


All times are GMT. The time now is 12:24 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01980 seconds
  • Memory Usage 1,776KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (16)bbcode_code_printable
  • (10)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (20)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete