Run a JavaScript function from a URL - javascript

I need to link to a page that uses javascript to create the appearance of different pages. Each of the links on the page I am pointing to calls a javascript function that produces the "new" page. So, if I just link to the page, I get the default configuration. But what I need to link to is a particular configuration after the js function has run.
At first I thought I would be able to append the function to the url, but apparently that functionality is not supported for security reasons (is this correct?). Is it possible to post the values?
Does anyone know how I can display the correct configuration?

In the general case, no, it's not possible, which is why these sort of JavaScript-only pages are an inaccessible, unusable total pain in the neck and people should stop creating them, the idiots.
If you are lucky and the site you're talking about has actually Done It Properly, then they'll have used #fragment navigation, so when you click a link it does a history-able and bookmark-able navigation, updating the URL to one with a #something at the end that you can use to navigate back there. If you're really lucky, there might even be a fallback URL for non-JavaScript browsers that you could link to. But more often all there is is a JS function, which you can't link to or invoke outside of that site, leaving you quite out of luck should you want to deep-link anything.
(Did we learn nothing from the <frame> fiasco, guys? All you trendy webmasters hacking up clever-clever swooshy jQuery-animated load()-powered multiple-pages-in-one sites are churning out rubbish that is no better than the frame-addled worst of the Netscape 3 era. Stop it. Seriously.)

Okay, I was given the solution by a friend. It seems I should answer my own question. In fact, I felt a little silly once I saw how simple the solutions was. I just forgot how to plant "posts" in a URL. It seems the question itself was erroneous.
All I really needed to do was set some Javascript variables in a page I don't own. Solution looks something like this.
http://www.apage.com/control.aspx?var1=someVal&var2=someVal...&varn=someVal
Thanks to those who responded.

The owner of the page could do you a favour and provide a mechanism to run functions depending on a value in the querystring.
Otherwise there may be something that can be done with ajax but it could be messy.

Related

Add some characters to the end of URL

I use a WordPress theme that has a number of custom post types. When I search for these post types, in the results page, the display order is from the oldest post to the newest post, but I want the newer posts to be displayed first.
I didn't design this template, so I don't know how to code it.
I found that by putting orderby=new at the end of the URL of the site, the display order is fixed.
Is there a way to automatically add this phrase to the end of the URL when someone enters the results page?
The links are like this: mydomain.com/activites/?location_name=paris&location_id=&taxonomy%5Bst_tour_type%5D= to the phrase mydomain.com/activites/? It is constant in all searches and after that, it changes based on the term that the user searches for.
The word location is the post type and the rest of the parts that come in the url are taxonomy.
immediate answer:
Write the link to the page accordingly. All other solutions will require changing some of the code or settings.
From my understanding of your question the cleanest solution is probably just to include a link back to the page itself with an added &orderby=new
Label the link in a way that makes it obvious to the user what it does. In this case I would assume ordering some type of content by release or entry date.
recommended solution:
Change the script in way that makes that order the default. It seems to be what you ideally "want". But can't do. As implied by the question.
janky solution:
Add a redirect. It's the same thing I said before but automatic without user input. The only benefit to this is being able to avoid touching existing code. And apply to all users as default.
roundabout solution, that will make maintenance a nightmare long term:
Rewrite rules in your web server. If you don't have access to that: try .htaccess
But since this modifies the behavior in a not immediately obvious way if is missing. And this will be easily missed by merit of being a hidden file and this type of config override not always being allowed. This might lead to non intuitive problems in the future.

JS Page Searcher

I need to bruteforce through pages and check it's contents for certain text.
ie. I have page: http://example.whatever/internet?ip=$4.2$$.$$6.$$$ and those dollar signs, are missing numbers. I need to go through all of existing combinations untill 404 - Page not found text isn't present on that page anymore (it's not an error code, that gets returned, just the text.)
I also need to be able to use it when there is login required to access the pages, and I have the necessary access, that's why I suggest JS to be used in this, and not server side script, like PHP or Python.
Edit 1: In case you want to complain, that this is not a question, I'm asking how to do it. And if you don't have the balls (or whatever it is you have or don't have) to comment bellow, why you did press that arrow down next to this question, so we can resolve it, please don't do it. Thanks for understanding.
I'd recommend using something like PhantomJS for this. You could login then iterate through pages until you find a non-404 page.

How do toolbars like the Meebo Bar work?

Meebo's new 'bar' service puts a floating bar with links and chat functions at the bottom of any given webpage with just a dash of Javascript and HTML. I'd like to build something like it, but I'm flummoxed as to how they got around the same origin issues.
It looks like they're injecting an iframe and some script tags, but how they accomplish the rest of the functionality without a proxy is beyond me. Any ideas?
You can check out Meebo's service http://bar.meebo.com/ there and Robert Scoble seems to have it setup over on http://scobleizer.com.
NB: I don't mean to be a shill for either Meebo or Scoble, I'm just curious about the implementation.
HTTP GETs can be across domains, so part of the magic is in what method you utilize. There are also other methods for sending data to a different host than the one serving the page, like the window.name trick where information (usually less than 2k at a time) can be set to the window.name property (here is a link)
You can also utilize a little Flash player (flXHR works great)
Smart JavaScript can actually utilize which ever one is available. Also don't feel bad for shilling for Meebo those guys rock!

Creating new html in JS or ajax loading a html layout?

I have a page where I need to create a large amount of HTML that's not already present in the page.
Using jQuery I've been building the page with JS piece by piece, adding divs here and there, etc, until I get my layout.
Right now I'm thinking rather than do all that in JS, I can create the layout in a separate HTML file and then load it with ajax. My initial aversion to that idea is because of ajax, it requires an additional server request, and might end up slow(er?).
Anyone have any advice on whether or not this is a good idea, and if it is, if there are tutorials, set ways and patterns to doing this sort of thing.
Thanks.
There may be a speed impact from making another round-trip to the server. However, I think that the readability/maintainability you gain from having all of your HTML in a separate template, rather than mixed in with your JS is the big win here. You won't have to deal with quote issues, entity encoding, all of that. And the code that you do have will be easier to debug.
I'm not aware of any specific tutorials on this, but with most of the AJAX libraries out there, it's easy to make an XHR request and pipe the response into a DIV. For example, see Prototype's Ajax.Updater(container, url[, options]) function. ( http://www.prototypejs.org/api/ajax/updater )
The issue you'll get is not slower, but your URLs will be a little messed up.
If you navigate from page to page your URL won't update easily. You CAN do it but it can be a lot of work.
I've used post's callback function to display the data from the post with good effect and it's fast.
Good luck with it!
edit: I was talking about jQuery's post function.
2nd edit: If you're going to vote me down guys, at least say why...

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.
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?
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.
Use a cookie or set a hidden field value. My vote would be for the field value.
This might be a cute case for using window.name, 'the property that survives page reloads'.

Categories

Resources