chrome extension problems in content_script - javascript

i have my Main.js file in content_scripts. Main.js file provides a button and when the user click the html page is saved with reloading the html page.But when user clicks button for a second time the button is not working as some of the previous values where set when the button were clicked first time.Is there any way in chrome than Main.js will be automatically reload or execute as fresh script on every click.Windows.onload methos is not working on my Main.js file so how i solve this

It's not possible you can use location.reload function

Related

LOad JS script, when user press the back button on browser

I have a js script code and I want to use only, when user press the back button on browser (load js script on the new page).
Is it possible?
You can't use the browser buttons to trigger any event on the page, so what you're trying to do doesn't seem to be possible.

page load without refresh and clear to memory for scripts

I am developing an MVC web project. I clicked the button and then load the page without the refresh. So far okay but my script codes are working 2 times when I click the button again. My problem is explaining to step by step:
1- I click the X button and then load the X.cshtml without the page refresh into the #currentPage element. There are x.js in X.cshtml
2- x.js script codes are working.
3- I click the Y button and then load the Y.cshtml without the page refresh into the #currentPage element. There are X.cshtml in Y.cshtml
4- x.js script codes are working 2 times.
5- I click the X button again, however, x.js script codes are working 3 times.
A sample simple project
I think I need to remove the variables,functions etc. from memory right?
How to solve this? Thanks.
I assume that in the x.js an on-click listener is defined. Each time that you load the script a new listener is put on the button. Before loading the x.js you should remove the click listeners from the button $('#button').off('click');

Calling a variable from a function in a different JS file

I am working on a chrome extension and I am stuck. I am not sure if this is even possible but this is what I need to have done. Basically the user click on the chrome extension and panel opens up (popup.html). The user is shown a list of images from the web and the user can select the ones they want to edit. popup.html loads popup.js. popup.js contains functions and inside those functions are some variable. Now there is a button in popup.html that takes you to another panel called filters.html. This is where editing goes. I am trying to pass the selected images from popup.html to filters.html and I am trying to call that array of images that was gathered in popup.js when popup.html loaded but its null. What is wrong is this even possible? When a new html page opens up does that mean it loses track of what happened in the last html page and therefore it loses also track of whatever .js files ran in that same page?
A new and better way is to use chrome extension storage. You can store the data from one page and u can read it in other page as data will be stored in chrome itself. Hope it helps

How to include javascript file in to dynamically created modal window?

I have a photo gallery that use modal window to display photos. During modal windows initialisation I'm inserting rest of photo functionality (share button, comment, tags, etc). Everything works well except facebook share button. From documentation you have to include following html code:
<a name="fb_share">share</a>
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share"
type="text/javascript"></script>
It works perfectly for static pages, but not with the pages that created on the fly.
Here is example of my javascript code (using jQuery)
//Insert share button
$.gallery.facebookLike.insertAfter($('#cboxContent #cboxLoadedContent'));
//Insert script element after share button
$('<script />', {
src : 'http://static.ak.fbcdn.net/connect.php/js/FB.Share',
type: 'text/javascript'
}).insertAfter($.gallery.facebookLike);
As result button inserted but script element is not initialised, after inspection in firebug this script appears in loaded script tab but not present on HTML tab. However if you click on the share link it sends you to facebook page and when you click BACK button in your browser the script gets initialised.
What am I doing wrong and what can be done about it?
I'm just taking a guess here, but I believe the script has a function running on window onload event. Since the window is already loaded, the script isn't running.
Edit: Yes, it seems that the function FB.Share.stopScan is being run on window load. You should try manually calling that function.

iFrame file upload with IE produces download dialogue

I'm developing a custom module for Drupal dealing with Document Management. At this point, the module loads, you can upload files (via a hidden iframe and some ajax requests), browse directories and set various levels of permissions. And everything works perfectly in Firefox.
Issue:
In IE however, I run into an issue. For some reason when I upload a file the save file dialogue pops up and asks me to download the file I just uploaded. It looks like it's asking me to download it from the web-servers tmp location however, as that seems to be the file-name and such. However, if I hit cancel and refresh the page I can see that the file I uploaded did actually get uploaded to the server.
Here is how the upload process works. Click the upload button. The upload button is the standard file input form element hidden and placed over a styled version of the button. Clicking on this causes the "Choose a file" dialogue to open.
Select a file and click "Open". A modal dialogue pops up asking you for some further information about the file. The modal is part of the same form element but remains invisible until you click Upload button
Clicking save in the modal causes the file to be uploaded. The "action" attribute on the form is pointed to a page and the target is the iframe.
The iFrame is polled a few times every second to see if it's contents have changed. When the file is uploaded a "success" message appears in the iframe. Since it belongs to the same domain, I scrape the content within the iframe.
Once the iFrame says that the file has been uploaded, I use some JS to update the application with the name of the file
Since I can't use Firebug in IE, I have to stick to utilizing Microsofts Web Developer Toolbar, which makes it very hard to figure out if the bolded step is actually occuring. It seems like it should, since the file IS being uploaded. It is just getting interrupted by that file download dialogue.
Since no one seems to have an answer, I'll post the fix I found. I doubt it's perfect, but it's the best solution I could come up with.
It turned out to be an issue with the polling as suspected. The fix ended up being instead of outputting json to the iFrame, just output some JavaScript that calls a function that updates the main window. That simple.

Categories

Resources