jevakallio
jevakallio

Reputation: 35890

Executing JavaScript on page load selectively

Mending a bug in our SAP BW web application, I need to call two javascript functions from the web framework library upon page load. The problem is that each of these functions reloads the page as a side-effect. In addition, I don't have access to modify these functions.

Any great ideas on how to execute a piece of code on "real" page load, then another piece of code on the subsequent load caused by this function, and then execute no code the third reload?

My best idea so far it to set a cookie on each go to determine what to run. I don't greatly love this solution. Anything better would be very welcome. And by the way, I do realize loading a page three times is absolutely ridiculous, but that's how we roll with SAP.

Upvotes: 1

Views: 892

Answers (4)

Marijn
Marijn

Reputation: 2096

This might be a cute case for using window.name, 'the property that survives page reloads'.

Upvotes: 0

user1921
user1921

Reputation:

Use a cookie or set a hidden field value. My vote would be for the field value.

Upvotes: 0

Wes P
Wes P

Reputation: 9870

A cookie, or pass a query string parameter indicating which javascript function has been run. We had to do something along these lines to trip out a piece of our software. That's really the best I got.

Upvotes: 1

Michael Haren
Michael Haren

Reputation: 108246

A cookie would work just fine. Or you could modify the query string each time with a "mode=x" or "load=x" parameter.

This would present a problem if the user tries to bookmark the final page, though. If that's an option, the cookie solution is fine. I would guess they need cookies enabled to get that far in the app anyway?

Upvotes: 2

Related Questions