Access custom URL on link click (userscript) - javascript

Im looking for a way to open an edited URL when I click on a certain link on a certain page, using userscript.
But I want to be discreet, so without
editing the the DOM (not changing the href url)
sending any request to the original url
Im not quite sure if #run-at document-start is fast enough to detect and redirect url before accessing the original url. I feel not.
Can anyone point me to the right direction? is it even possible?

Related

Another request is redirected but the previous url stay unchanged

When I mouseover edit at the bottom of stackoverflow's question like
javascript - How to call an AJAX function on anchor tag?
It's url address appears as
https://stackoverflow.com/posts/18779494/edit
However, if I clicked the link, an edit form emerged but the url address stayed unchanged,
It's not https://stackoverflow.com/posts/18779494/edit but still manifest itself as https://stackoverflow.com/questions/18779494/how-to-call-an-ajax-function-on-anchor-tag
How to perform this magic tricks?
It is intercepted via javascript which also stops redirection but incase the javascript is disabled or there are some JS erros you would be redirected to the href. It's a best practise to have your website work without JS as well.

Possible to make webpage URL the same as an iFrame URL?

So I have an iFrame which I am using to load the other pages for my website. To make the website seem like it has no load time and very smooth I have made a main page, with an iFrame in the middle to load the actual pages of the website that contain all the information. I have buttons using JS to change the SRC of the iFrame so that it acts like a normal nav bar.
I am curious to know if it is possible to make the URL on the browser, the same as the URL in the iFrame. Because right now when a user is on the website, they aren't switching to different pages, meaning they can't go back or forward in history because they never left the page in the first place. This can be troubling to most users if they want to link their friends to something, or just go back a bit.
Is there a way to do this in jQuery or JavaScript? Or even better, purely in HTML or CSS?
Thanks in advance.
EDIT: After googling a bit of what charlietfl has said, I am now wondering if it is possible to save a website into states, which I can then give web URLs to? I just skimmed through a few pages without reading them thoroughly so I'm not exactly sure what it was talking about when it mentioned states, but maybe there is something else out there that is capable?
You can try url hash like the gmail uses #inbox . It has the same functionality as you wish. It serves you the browser back and forward actions. You have to add more Javascript to handle those hashes. But i am not sure about its effect on seo (if you are only concerning about it).
For more details please go through these links
Gmail like URL scheme
Browser History Manager

How can I get links to a redirect page to show up in the browser's history?

A website contains a "random" link, which loads a url that returns a 307 redirecting to the url we want. It works fine: click it and you load a random page. The problem is that each time you click it, the browser assumes you're loading the same page: so if you're on the homepage, then you follow the random link 5 times, then you press back, you'll be taken all the way back to the homepage, with no way to find the random pages you were just looking at. I want to modify this behavior so that users can access previous random pages via the back and forward buttons.
I don't own the website, so I can't just change the redirect code.
Here's what I've tried, all of which has failed.
Predicting what would be redirected to. While somewhat possible, there would be no way to avoid failure in up to .1% of clicks, and it would react very poorly to unexpected events, like a page that's published a day late, let alone a sit structure change.
Loading the 307 page via ajax. The request stops at readystate == 2 and I can't access the location header.
Cancel the click event and instead set location.href = random_link.href. This has no effect - the new page still doesn't go into history.
Have the new page call history.pushState. This successfully adds the page to history, but I can't find a way to distinguish between new pages and ones being opened via the back button, so the history quickly becomes very corrupted.
Keeping my own history in localStorage. As above, I can't tell when the back button is being used.
I'm working on a solution that I'm pretty sure will work, involving loading the page in an iframe over the existing page and using a background process and messaging to work around the fact that content injections from chrome extensions can't access window.parent from within iframes. And using the history API to reflect the current iframe's URL in the address bar, and get the back and forwards buttons to apply to the current iframe where appropriate.
While I'm pretty sure the last solution can be made to work, it's a hideously complex and heavyweight approach to what seems like a simple problem. So I thought I'd ask you guys before I continue: any other ideas?
Have you tried storing the locations in localStorage, then hi-jacking the back button ?
I am sure you know how localStorage works, for hi-jacking the back button you can refer to this : Is there a way to catch the back button event in javascript?
T.

Append to URI/URL live without refreshing the page location with JavaScript/jQuery

What I have is a MVC framework that I am manipulating the DOM via JavaScript and jQuery. Which to a point is a mute reference to this question. Through the MVC if I go to
domain.com/page/
I land on a default page with recent info, updates, etc. However through the MVC if I go to something like
domain.com/page/ref1/ref2/ref3
We can handle that on the backend to do what we want. When its gone to directly. So the thought here for this question is, can I mimic the behavior cross browser up to at least up to IE 6/7+, Firefox 3.x+, Chrome. And by mimic I mean manipulate the URL/URI like I would the DOM itself. This way when someone comes along and navigates to sections via the methods we manipulate the DOM and find something they want to share all they have to do is go up to the browsers URL bar, and then copy and paste it to a message.
What would be even nicer is a method that can work with the back and forth history buttons on browsers as well. All without having to reload/refresh the page.
have you tried
window.location.replace(URL)
This function doesn't load any pages.If you change your current location like this , when you redirect to somewhere , your last address will be the non-modified address.It doesnt write new URL to the browser history.So it would be like as if you just give the key to what the user wants to share.
Have you considered modifying the anchors in the URL? While on this page:
http://www.google.com/
Changing the URL to this:
http://www.google.com/#foo
... won't trigger a page refresh. So you could use (read/modify) the contents of the URL after the anchor all you want and the page won't get reloaded. Should be able to build on that idea.

What's the most reliable way of getting a page's referrer in IE?

From within a browser extension (BHO) I want to know the URL that referred a user to the current page. I thought I could just get the document.referrer, but I find that's blank if links are opened in a new window. Is this just tough bikkies or can I use opener.location.href in some cases, or something else?
As a follow-up, I'm currently getting this when the page has loaded, ie on DocumentComplete, but I'd prefer to get it on BeforeNavigate2. I don't see any way to do that except use the current location as the referrer on BeforeNavigate2, however that will give me the current page as a referrer if users enter a new URL in the address bar. ie it'll look like they navigated from a link on site A to site B where actually they went to site A then typed in the url for site B.
UPDATE:
From what I can tell, sometimes the 'opener' property will be set (if the window has been opened from javascript?) and therefore we can get the effective referrer page from that. Anyone know specifically in which situations this is available?
The only way to get this information is from the HTTP referrer, so unfortunately you may be out of luck for any situations in which that header value is blank.
Unless you owned the page that has the link to a new window, and add a hash or id or something identifying to a session or to the link, you will not be able to capture the referrer.

Categories

Resources