external javascript in iframe always reloading - javascript

I have a div with a <script scr='highcharts.js'> that is embedded in the code of that div.
My application will rewrite the source of that DIV every now and then, and write a bunch of new code. It will also rewrite the tag. Every thing works fine (highcharts is working). But because of some other constraints it is quite difficult to write the tag in the main body of the page. (It will take to long to explain exactly why... I hope my question can be answered without :-) )
The strange thing is: when I look with firebug, I can tell the script is being reloaded everytime I rewrite the source of the DIV! There is even some kind of id added to the URL:
/highcharts.src.js?_=1328861301862
I'm not doing this! I don't recognize the ID as anything in my app... It seems that every browser is doing this, so it is not specific to FF. Why is this happing, and is there any way to prevent this?

If anyone wonders how I solved this: I ended up using require.js. This solved the problem neatly :-)

Related

Webbrowser control onclick event

I have a code that clicks an html element but it doesn't fire its java script code, in VBA I used to call "initEvent" in order to invoke a java script event.
I have searched the web and haven't found a suitable solution.
There's a working solution, but it's not quite useful in most cases, placing a java script code in the url and navigating to it, however there's a need for the location of the html element which is a problem sometimes.
The code I use in order to do a click in the html element :
el.InvokeMember("onclick");
Also tried :
el.InvokeMember("click");
The code that I place in the url and find not too much useful :
wb.Navigate("javascript: document.getElementsByClassName('something')[0].click();void(0);");
I hope to receive a working solution, thanks in advance.
I've solved it, a very original solve I'd say.
So basically, I've thought about it this way.
Finding an element that I already have is not comfortable at all, so the java script navigate didn't seem useful, however, I thought of changing it to fit any element, the question was how.
The answer I came up with, what if I'd focus the specific element and then use a javascript to click on the focused element, and it worked.
So the fixed code :
el.Focus();
wb.Navigate("javascript: document.activeElement.click();void(0);");
I hope it'll be useful to some of you.

Difficulty sending values to input fields (sounds ridiculous)

EDITED: New information: When I inspect the field, and the code is highligted (in the inspector), then the statements all work as they should, but when the field isn't highlighted anymore, the statements do not appear to work. Hopefully this helps diagnose the issue.
I have a wufoo form (a hosted form that you can embedd, send to spefic email on submit etc). I have a field on that form that I am trying to populate with a certain piece of data once I click a button. I believe I have the correct code to make this happen, and it should work:
$('#my-button').click(function() {
$('#Field3').val("something");
});
I have tried many different ways:
$('input[id="Field3"]').val("something");
$('input[name="Field3"]').val("something");
and a few reaches which I didn't really think would work..
$('#Field3').append("something");
$('#Field3').text("something");
There are a few things that confuse me here, and I will post screens below showing what I mean. I can type all of these commands in the console once the page is loaded and nothing will happen to the field (with the id of Field3)...most of the time. But on several occasions, I would reload the page, try a few statements again, yes the same ones, and then it would work. No idea why or how, but it is sort of an intermittent thing. Obviously that's probably not the case, but I am pretty confused as to why this is happening;
Below are three screens of my console. For the first two, the field finally populated after about 10 or more tries in the console, and then continued to work while using commands that didn't work before. The last screen is an attempt that did not work at all:
[![Eventually Works After Last Command][1]][1]
[![Eventually Works After Last Command][2]][2]
[![Did Not Work][3]][3]
[1]: http://i.stack.imgur.com/JKVxY.jpg
[2]: http://i.stack.imgur.com/MLca8.jpg
[3]: http://i.stack.imgur.com/0viRA.jpg
(Apologies for the way I had to post these images, I keep getting formatting errors that will not let me continue to save the post unless I cmd+k them)
I try everything in the console first, but I can not find any patterns here. Any ideas or input would be greatly appreciated, and thank you for your time.
At this point I'm pretty sure the problem has to do with the form-code switching or adding certain classes under certain conditions, so I downloaded the code from my Wufoo account rather than embedding it. Then I only added the code for the view (not css or JS), and it works now.
My original statements (not the reachers) all work fine now when I try them. Thanks for the time everyone.
I know you solved your issue, but figured I'd chime in in case you or others have this issue again in the future. It sounds like your issue was related to execution order. Wufoo's embed scripts are asynchronous, so it's very likely that the input fields in question didn't yet exist on your page at the time your jQuery click handler was evaluated. Changing your original code to jQuery's "on" method instead of "click" would likely have solved your problem, as "on" provides a delegated event listener. At any rate, glad you got everything sorted out!
In the console I assume there is no jQuery loaded.
I usually write:
document.getElementById('Field3').value = "something";
Updated your Jsfiddle. The only thing I changes, I added the reference of the
Jquery. Might be that's the problem.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

Run Javascript/jQuery inside iframe

I'm currently working on a web editor where you can enter your HTML, CSS and JavaScript code and see the result in real time. Something similar to JSBin or JSFiddle. (I'm doing that to get an offline editor)
I've already been through many problems especially when it comes to CSS but I solved them by using an iframe and injecting all my code into it. And that works amazingly well until you type some JavaScript.
I'm sending the code between <script></script> but unlike CSS it won't run. What's very weird is that when I enter something like $('button').css('color', 'red');, the buttons of the editor effectively get affected but not those of my iframe. Exactly the opposite of what I expected. I've tried many things, looked at many topics on the forum, but nothing works. I also tried to load a blank page in my iframe. In that case, JavaScript runs but it becomes impossible to edit the code in the iframe! What's going on? Where am I going wrong? Thank you in advance for your help!
Here's my editor : https://jsbin.com/tuqite/edit?html,js,output/
Try updating the content of the iframe like this.
// this string contains both html and script
var html_string= "content";
document.getElementById('childFrame').src = "data:text/html;charset=utf-8," + escape(html_string);
By directly updating the iframe DOM like the way you are doing may not be the right way .

Gap above header breaking page in Chrome/Opera

I have a gap appearing above the header of my page in Chrome and Opera which is breaking the navigation and other parts of the page. Please see here.
I had this exact same problem before rebuilding my site but can't for the life of me remember now what the problem was or what I did to fix it... hopefully it is not something too stupidly simple and obvious, and allow me to apologize in advance if it is, but I'm feeling a bit too mentally drained to even think straight enough to figure it out at the moment, despite my best efforts.
I suspect it may be somehow related to the simple PHP script which randomly loads either index1.html or index2.html from the root directory, since if you go to either URL directly (ie. http://samnorris.co.nz/tesla/index2.html) the problem is no longer apparent... I'm not sure if some kind of invisible error is being spit out or something which is breaking the page?
This is the PHP script which is contained in an index.php in the root dir
<?php
$randNumber = mt_rand(1,3);
if ( $randNumber == 1 )
{
include 'index1.html';
}
else
{
include 'index2.html';
}
?>
I have checked the Web Inspector tools in Chrome but am not overly familiar enough to know how to interpret it properly, there seems to be one small error relating to part of a script in siriwave.js - but I don't think it is related...
I'm at a bit of a loss, so any help at all would be appreciated!
The response of http://samnorris.co.nz/tesla/index2.html and http://samnorris.co.nz/tesla/ are not the same.
http://samnorris.co.nz/tesla/index2.html
http://samnorris.co.nz/tesla/
Due to the presence of <U+FEFF><U+FEFF>
The whole parsed HTML is getting malformed for http://samnorris.co.nz/tesla/
The tags specified within head are appearing within body.
What is injecting these <U+FEFF><U+FEFF>extra characters?
You should try using W3C Validator
<head></head> element is empty. Your meta,link, tags are below your head.
Okay, definitely solved it this time. Seems this was the issue: http://wordpress.org/support/topic/weird-characters-inserted-before-doctype
something to do with incorrectly formatted UTF encoding in the php file... very weird indeed.

Google Chrome Extension

I have a few questions that need answering. I am trying to create a Google Chrome extension and I need every page to be monitored for a keyboard action. I have added a content script that runs on the page load and when you click the keyboard shortcut an alert is shown.
What I want to do is instead of an alert have something like fancybox, thickbox, etc... however all of those are jquery plugins which adds a dependency to my js file. I tried launching the plugin before my js file but it still does not work.
I run the content script from the manifest.json file with
"content_scripts": [
{
"matches":["http://*/*", "https://*/*"],
"run_at":"document_start",
"js":["jquery.simplemodal.1.4.1.min.js", "shortcuts.js"]
}
],
I cannot execute an HTML page where the js is located I have to use a js file.
so what I want to know is if either there is a way to include the plugin without physically adding it to my file or if there is a way to call the js file which then just executes an HTML file or if there is another way of creating a popup screen like fancybox that is already included in js.
Another question I have is if there was a way to embed HTML into an alert box (this is a backup if I cannot figure out the above question)
and finally does anyone know of an execution command for x-webkit-speech? I want the command to start recording and somehow some people have used some commands (none of which answer my question) so someone somewhere knows a little more about this function then me. I would really appreciate help with this I am really close to finishing my program and these are my last holdups with these questions answered I will be able to release my extension. Please help where you can I have researched and researched everywhere all different ways of trying these things and none have worked.
edit:
You were correct (JHurrah) including the jquery actually solved the problem I really appreciate that. simple yet successful I just assumed the jquery provided was enough but I guess everyone knows what happens when you assume especially when programming.
NewTang I have already looked at that website however I will relook at it and see if I missed anything thanks for the help
yeah see I don't have that I have link edit and flag I looked all over and did not see an add comment button at all... :[
since simplemodal is a plugin it depends on jquery, try including jquery in your manifest before the other scripts.
"js":["jquery-1.5.2.min.js", "jquery.simplemodal.1.4.1.min.js", "shortcuts.js"]
I"m a little confused by your question, but I'll give it my best shot.
1) I think you're trying to ask: Can I use a content_script to inject HTML. The answer is yes, but only through Javascript. So, you could have something like:
//using jquery
$("body").append("Hi, I'm on the bottom of the page");
Your javascript would have to create or load the HTML that would get inserted into the page.
2) No, no HTML in an alert box. You're on the right track with using lightbox, thickbox, etc.
3) There's not many resources on x-webkit-speech, but maybe this can help you get going: http://nooshu.com/experimenting-with-webkit-form-speech-input

Categories

Resources