I am getting the value "msg" from the page http://www.kimi007.freeiz.com/frame.html with the following code (address must be in the address bar and then you hit 'enter', thus getting the alert message "success!"):
javascript:
(function()
{
var%20s=document.createElement("script");
s.setAttribute("type","text/javascript");
s.setAttribute("src","http://www.kimi007.freeiz.com/java.js");
document.getElementsByTagName("head")[0].appendChild(s);
}
)()
The above has these two lines in the .js file:
var capForm = document.getElementById('form').elements[0].value;
alert('' + capForm + '');
I have no problems up to this stage. However I want to put "frame.html" in an iFrame like this:
http://www.kimi007.freeiz.com/test.html
and have my Java code work so I can get the same "success!" message from within the iFrame. Any ideas on how to do this?
Thanks.
try the following code, might do the trick:
top.frames[name_of_the_frame].some_function()
Related
Hello,
I am trying to test error supression on Sharepoint but I am having some trouble.
This is my process:
On a relatively plain website (all it contains is a colored-in div), I added this script:
<script>
var x[] = 0;
var err = 10/x;
alert(err);
</script>
When setting my Outlook homepage to this site, I see this error:
I also have the following script, which suppresses this message (when adding this to my code, the error message doesn't appear):
<script type="text/javascript">
window.onerror = function(message, url, lineNumber) {
// code to execute on an error
return true; // prevents browser error messages
};
</script>
I want to test this script out on my Sharepoint site, but when I embed the above, error-inducing code onto my Sharepoint homepage and open the page in Outlook, I am not seeing any error messages.
I added the code in the following ways:
1 - Page > Edit > Edit Source > Added the code to the top
2 - Page > Edit > Embed Code > Added the code to various areas of the page
Neither of these methods worked, and the first one actually produced a message telling me that I should use the embed function, which also doesn't seem to work!
I need to generate this error from the Sharepoint page so that I can check **whether the error-suppressing script actually does what it's supposed to. Can **anyone think of what may be going wrong here?
Any help is much appreciated!
This is apparently a known issue in Sharepoint, and can be resolved by using the following function:
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
//your code goes here...
});
For the purposes of the above test, I was able to generate an error with the following:
<script language='javascript'>
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
var x[] = 0;
var err = 10/x;
alert(err);
});
</script>
And adding the below suppressed the errors:
<script language='javascript'>
window.onerror = function(message, url, lineNumber) {
return true;
};
</script>
Note that this only worked for me after adding the 2 bits of code in their own, seperate <script> tags. I also had to add language='javascript' to the tags before it would work.
I added the code by embedding some new code, and adding both of the script tags to that web part. Because I was able to produce the error message, I was also able to prove that the error-suppression method worked.
I found questions regarding "extension not able to connect in new tab",where the solution is to use chrome.tab module, but din't found anything like this:
I am stuck at this from many days, I will be glad if anyone could help me around.
I am using extensions for cross Domain calls, but my webpage can connect to the extension (I think content script) only when my page is a pure html page.If I change my page's content using:
document.open();
document.write(html);
document.close();
(I did this keep the url of my webpage same when a user log in)
I cannot get any Response from extension.
Is there any solution which I am missing.
code for Reference:
HTML where I replace page:
PageLoader.prototype.loadHTML = function(html) {
if (history.pushState)
try {window.history.pushState(null, null, document.URL);}
catch (e) {};
document.open();
document.write(html);
document.close();
};
crossDomain Code:
this is function which is called on click of some button
`window.addEventListener( "message", function(event) {
if (event.source != window ) return;
callback(event.data.text);
});
window.postMessage( { type: "com_logincat_xhr_get", url: url }, "*");
`
This postMessage is done but did not get any response from chrome extension's content_script.js (only If I have used document.write in my webpage to replace the content).
content_script.js also contain eventListner for message.
window.addEventListener( "message", function(event)
{
/* It contains piece of code to send message (chrome.runtime.sendmessage) */
};
I found at some places content_script.js attaches only at pageLoad and document.write might be replacing things, but I did not found any solution for this.
I think the code is correct as it works smoothly when page is a simple direct html.I don't know what wrong document.write do to my webpage
I Hope It will help,
Thanks for the help.
Hey this is my solution to the above problem.
I found that content_script.js of Extensions attaches to DOM only at pageLoad.
and using document.write('html')
I was modifying the DOM, which was creating Issue for the connection with content_script.js,
so I decided to use
document.documentElement.innerHTML = html;
using this I got into another problem which was that scripts were not getting executed which were in var html.
for that I did this:
var scriptToInclude = document.getElementsByTagName('script');
for (var n = 0; n < scriptToInclude.length; n++)
eval(scriptToInclude[n].innerHTML);
and it worked :)
I've been asked to include the following javascript in a project to make a widget appear:
<div class="nd-service nd-tyre-booking">
<script type="text/javascript">
var sourceDir = 'js/widgets/';
var widget = [
'http://<company-domain-is-here>.co.uk/',
sourceDir,
['tyre-booking', '4a68ff678d3d8fae7615519c977e5a5490cca00b']
];
var s = 'script', o = document.createElement(s);
o.type = 'text/javascript';
o.src = widget[0] + widget[1] + 'lib/require.js?';
o.setAttribute('data-main', widget[0] + widget[1]
document.getElementsByTagName(s)[0].parentNode.appendChild(o);</script>
Nothing happens though. I don't really know any javascript but it looks incomplete to me. It's referring to directories/files that don't exist such as js/widgets/ and lib/require.js
I've been back and forth with them asking for any kind of documentation and confirming that this is all that's required to make the widget appear, but they insist that it just needs to be pasted somewhere in the body and then it'll appear.
My javascript console outputs Uncaught SyntaxError: Unexpected identifier on the final line of javascript.
The line .setAttribute('data-main', widget[0] + widget[1] misses ")" and a ";".
It should be o.setAttribute('data-main', widget[0] + widget[1]);
And about the "does the script do anything" part, yes, it does. It defines a new script, fills it with something but... I fail to see the part where it is appended to the body.
I have no idea what is going wrong here. When I run this code on a website, it doesn't give an error.
It is meant to be ran from a bookmark in a browser to inject a script into a website, but I'm not getting the prompts to show.
var s = document.createElement('script');
s.type='text/javascript';
document.body.appendChild(s);
if confirm('Press OK to enter a url to the script/nPress Cancel to enter code directly')
{
s.src=prompt('Enter the url to the script file (javascript only):');
} else {
s.innerhtml=prompt('Enter code to inject (javascript only):');
}
void(0);
This is the version of the code that will be ran from a bookmark.
javascript:var s = document.createElement('script');s.type='text/javascript';document.body.appendChild(s);s.innerhtml=prompt('Enter code to inject (javascript only):');
You need to wrap if conditions in parentheses, eg
if (confirm('Press OK to enter a url to the script/nPress Cancel to enter code directly'))
The error I got with your original code was
SyntaxError: Unexpected identifier
The idea is to write a simple bookmarklet.
If the question is a possible duplicate kindly point me to it, because i was unsuccessful in finding.
I'm trying to make the current page jquery enabled using the bookmarklet and use certain jquery apis.
Uncaught SyntaxError: Unexpected token ILLEGAL
The above it the error I get using the below sample bookmarklet
javascript:(function(){
var d=document.createElement('script');
d.setAttribute('src', 'http://code.jquery.com/jquery-latest.js');
document.head.appendChild(d);
$('a').each(function(){
alert( $(this).attr('src') );
});
})()
If I execute the same code line-by-line in console it works.
Thanks in advance
To make the page wait until jQuery is fully loaded, add a load handler to the script element. This worked in my browser:
javascript:(function(){
var d=document.createElement('script');
d.src = 'http://code.jquery.com/jquery-latest.js';
d.onload = function(){ /* load handler here */
$('a').each(function(){
console.log( $(this).attr('href') );
});
};
document.getElementsByTagName('head')[0].appendChild(d);
})()
I changed your code a little bit (add the src attribute directly as property to the created script element, retrieve the head element in a more classical way, use console.log instead of alert and log the href attribute of all links).