Iztak
New Member
Posts: 9
inherit
261405
0
Apr 17, 2021 16:11:50 GMT -8
Iztak
9
June 2020
iztak
|
Post by Iztak on Jun 9, 2020 11:43:05 GMT -8
I am making a plugin with javascript I'd like to run ... - After page load
- On all pages of a thread
I can make it run after page load with this: $(document).ready(function() { But so far I can only get it to run either on the first page or on subsequent pages. With this code, it runs only on the later pages... pb.events.on('afterSearch', function() { Without that, it runs only on the first page. EDIT: Put another way, I need the javascript to be applied to every post regardless of what page it's on. Any help?
|
|
Kami
Forum Cat
Posts: 40,198
Mini-Profile Theme: Kami's Mini-Profile
#f35f71
156500
0
Offline
Jul 24, 2021 11:48:29 GMT -8
Kami
40,198
July 2010
kamiyakaoru
Kami's Mini-Profile
|
Post by Kami on Jun 9, 2020 12:05:37 GMT -8
I don't write javascript, but I expect the issue you're encountering is the fact that only the current page of a thread loads. So if you're on page one, only page 1 content is populated and any subsequent page content does not exist. When you switch to page 2, only page 2 content is populated and pages 1 and 3+ does not exist.
You'll only be able to run a script after page load for the current page. I don't know what js you'd need to accommodate for that, but you can't write a script that does all pages simultaneously simply because they don't exist as far as the browser is concerned.
|
|
Iztak
New Member
Posts: 9
inherit
261405
0
Apr 17, 2021 16:11:50 GMT -8
Iztak
9
June 2020
iztak
|
Post by Iztak on Jun 9, 2020 12:08:20 GMT -8
I need the affect to happen on every post regardless what pages it's on.
|
|
Kami
Forum Cat
Posts: 40,198
Mini-Profile Theme: Kami's Mini-Profile
#f35f71
156500
0
Offline
Jul 24, 2021 11:48:29 GMT -8
Kami
40,198
July 2010
kamiyakaoru
Kami's Mini-Profile
|
Post by Kami on Jun 9, 2020 12:21:06 GMT -8
I need the affect to happen on every post regardless what pages it's on. Like I said, I don't write javascript, I just wanted to chime in with the above information in case you were writing something that was attempting to find multiple pages.
|
|
Iztak
New Member
Posts: 9
inherit
261405
0
Apr 17, 2021 16:11:50 GMT -8
Iztak
9
June 2020
iztak
|
Post by Iztak on Jun 9, 2020 12:28:39 GMT -8
Yes, of course. Thank you! Maybe someone with javascript experience will be able to advise.
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,324
January 2004
todge
|
Post by Todge on Jun 9, 2020 16:17:47 GMT -8
You call the function twice, once for the first page, and again whenever you navigate from page to page within that thread.. $(document).ready(function(){ alert('hey'); proboards.on('pageChange', function(){ alert('hey'); }); });
|
|
Iztak
New Member
Posts: 9
inherit
261405
0
Apr 17, 2021 16:11:50 GMT -8
Iztak
9
June 2020
iztak
|
Post by Iztak on Jun 9, 2020 17:33:23 GMT -8
Thank you! That is what I needed!
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,324
January 2004
todge
|
Post by Todge on Jun 10, 2020 9:08:46 GMT -8
No worries..
|
|
#eb7100
33409
0
1
Nov 23, 2024 16:57:32 GMT -8
Brian
48,130
November 2004
smashmaster3
|
Post by Brian on Jun 10, 2020 10:13:18 GMT -8
I would personally write this as a function so that you don't have to duplicate code.
The bits I colored red are the opening and closing of a self-executing function. Writing code within it is the same as writing code anywhere, but since it's within the scope of a function any variables or new functions you declare within it won't exist in the global namespace which should prevent it from being overwritten by anyone else's code.
The line in blue is shorthand for jQuery's $(document).ready which you're using above. Typing a dollar sign followed by a function name between parentheses will make that function execute when the page has finished loading.
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,017
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Jun 15, 2020 13:20:46 GMT -8
It might also be important to point out something regarding the use of IIFE in plugins. From the discussion in the linked thread it appears to be fixed on PB's end on a case by case basis. The alternative and simple workaround is to give your anonymous function a name (so no longer anonymous ) which I've been doing ever since without further issue. I used to give my IIFE functions names back in the days since it also helped with quickly recognizing them during debugging/stack traces but fell off doing so until this issue cropped up again.
|
|