If a Greasemonkey script has functions running, and then navigates to a new page using window.location.assign(), is there a way to keep those functions running, and without the entire script reloading? I'm wondering this since Greasemonkey is a browser plugin, maybe it can keep working no matter what page you navigate to.
I don't think I can use Ajax, or an iframe since it needs to navigate to different domains.
Thank you for any help you can give!
I doubt it is possible. Greasemonkey is a browser plugin, but the script you created for a specific page works only inside this page, not globally. Once you navigate away, the script, part of the page you navigate away from, is killed, like the rest of the page.
Related
I need to create a chrome extension that for every web page te he user opens - he will have a button on top of the page (similar to the google translate extension - just that it will appear with page load, without the need to press a button) - preessing on it will do some activity.
from what i saw - the way to do it is to create a content script that will add an iframe that includes the button on the window.onload. just before i do that - i want to be sure there is no more simple way of doing that.
Thanks.
There is an experimental infobar API, but it's unknown when, if ever, it becomes stable.
As-is, you really need to inject your UI into the page DOM from a content script, with an iframe being a good solution to separate your UI from the page.
If it's just a button for each page then you could use a Browser Action
If you'd like for it to actually be in the page then an iframe is a good way to go.
I am trying to run a JS script on a website (not my own) and I want it to refresh the website, in order to check for updates. However, I have only found code online for reloading the entire page (location.reload(true), etc...), which clears any code that I have running through the console. I am new to JS so is there any way to refresh a page and keep the JS code running? Also might there be a way to only reload load a certain portion of the page?
Basically,
Reload website without stopping code
Using jQuery you can easily load any part of a page from a URL using AJAX. To fill the body element with the contents of a URL:
$('body').load('/page');
Your URL can respond with the segment of HTML you want to render, or you can request a full web page and grab just the segment you want buy adding a selector:
$('body').load('/page body');
The page isn't technically refreshed, just the HTML content inside the body (or whatever element you select) is replaced. Any previously loaded header content like JS remains and keeps running.
There is no way to actually refresh the entire page without stopping the execution of the JavaScript code.
For doing updates on the page there would be two possibilities:
Use of AJAX (Asynchronous JavaScript and XML) to check for new updates on the page. There are some very good tutorials out there on the internet – just google »AJAX JavaScript«.
Use of IFRAME. Make a page and stuck all the stuff in it and then put that page in an iframe and then reload the iframe instead of reloading the entire page.
Hope I could help you.
I've developed some javascript code that renders an iframe on the page. Inside the frame, it loads various API's for social networking, such as facebook, twitter, linked in, etc. It's basically a tool for the website to allow users to sign in with their social network. I've also created a simple jQuery plugin that loads this iframe into a modal popup.
Here's the problem:
The main iframe is loaded on the site, but the developer also wants to use the jquery plugin on the same page. It works fine, but ALL of the javascript is being loaded a 2nd time. So basically it is a huge waste of resources, as every social networking api is being loaded twice. I was wondering if there was a way to track that the api's have already been loaded, and to stop loading them again. The 2 iframes are exactly identical.
I tried adding some properties to window.top, but this doesn't work because of cross domain limitations. The two iframes are of the same domain, but the main site is a different domain.
I was also wondering if an iframe can detect if the main window has loaded jquery, as that is being loaded again even when it's not necessary.
Any advice and suggestion would be appreciated,
Thanks!
You should not use an iframe for this. It sounds like you are creating a 'login pop-up' for users to login, say if they clicked 'comment' and were not already logged in. Just use a div, and float it absolutely above the rest of page.
I'm trying to use Diigo with sciencedirect.com but apparently the pages are not static, they keep changing, but I can access the same paper through the same link every time. The problem is that this link then redirects the page to a dynamic one in science direct.
I was thinking, is it possible through JavaScript or Greasemonkey to catch the redirection and send it to an iframe, so that the main page could be the initial link?
An example:
http://linkinghub.elsevier.com/retrieve/pii/0924-8579(95)90674-L
I was tinking, is it possible trhough javascript on greasemonkey to catch the redirection and send it to an iframe, so that the main page could be the initial link?
No it's not possible to do this with Greasemoneky, you'd have to use a Firefox add-on in order to do this.
I am developing a website with some links to some pages on external websites (belonging to the same company).
The client wants to add a way to easily return to the home site, i.e. something better than just using the browser's Back button, and something better than just opening the external links in a new browser window.
Seeing as I can't control the content of the external pages, I'm guessing that I will have load those external pages into a frame somewhere along the line.
So is there a way for a link to load a local page with a frameset, with the external page loaded into one of the frames? (Then we could have a "Return Home" button in the other frame.)
Or is there a better way to accomplish this? I could stretch to a bit of JavaScript if pushed...
Thanks,
Stewart.
You'll need to display the external websites in an iframe, with a link at the top (outside of the iframe) back to your site. Note that some sites employ "iframe busters" which will get rid of your iframe.
The best option is to open in a new tab - it's how people expect the web to work.