I am trying to display an Ajax returned xml file in String format in IE9.
Since it is in String, IE takes all xml tags as un-recognizable html tags and tosses them away. Only text data are display and it is really a mess. I can use <xmp> or <pre> but then when I save the xml by the file->save as..., the <xmp> <pre>is there. I do have the option to select all from the web page and copy paste to some text editor but in my case it is preferrable to use save as.
So I tried to escape all those < and > with entity reference in Java with StringEscapeUtils.escapeXml(). But still the problem persists. Do I have it right in Java? And is there any simple way to display xml input stream (not a file) as-is in a brwoser?
Here is the Java code for Ajax service.
public String retrieveXML() {
String unescapedXML = getXMLByRestfulService();
formatXMLMsg(unescapedXML);
String finalXML = StringEscapeUtils.escapeXml(unescapedXML);
return SUCCESS;
}
Here is the Ajax client code. Some parameters can be safely ignored.
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();a
} else if ( window.ActiveXObject ){
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if ( req ) {
req.onreadystatechange=function(){
if ( req.readyState == READY_STATE_COMPLETE ){
var myXML = req.responseText;
var myWin = window.open("", "aWindow", "width=800, height=500");
myWin.document.write("<xmp>"+myXML+"</xmp>");
myWin.focus();
}
};
req.open("POST", url, true );
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send (params);
}
I'm a little unclear on your question in regards to "as is" in browser. But, I'll take a shot.
You may need to enable the XML DOM plugin.
Click Tools(gear icon)->Manage Add-ons; this will pop-up a dialog
select "All add-ons". I don't have IE9 loaded, but you need to (may look like below):
Find "XML DOM Document" add-on and make sure its enabled
Close all IE windows and retest
Just to get you up to speed, I have set-up my CKEditor instance so that when viewing the WYSIWYG (live) mode [image:abc123] is replaced with the actual URL to the image.
So for example in the HTML source view, you see this:
<img src="[image:abc123]" />
But when you view the WYSIWYG (live) mode, it shows this:
<img src="/file/image/abc123" />
This is all working great. An issue I am now having is when you edit the image in Image properties. As the image does not exist, it show's the red x.
http://img405.imageshack.us/img405/104/jzny.png
My question is, is there a way to customise the Image Properties dialog so that if it matches [image:abc123], it loads a different image URL in the Preview window?
This code doesn't work but might make it a little clearer what I'm trying to achieve here.
CKEDITOR.on('dialogDefinition', function(evt) {
if (evt.data.name == 'image') {
var image_url = ???;
var preview_image = ???;
var file_id = image_url.value.match(/\[image:([a-zA-Z0-9-]+)\]/);
if (file_id)
preview_image.src = '/file/image/' + file_id[1];
}
});
Thanks in advance!
I have a pdf inside an iframe and a description text beside it.
In the text, I have links which should scroll the pdf to the desired page.
$('a.pdf-page').click(function(){
var iframe = document.getElementById('#pdf-iframe');
var page_no = $(this).attr( 'data-page' );
iframe.contentWindow.location.hash = '#navpanes=0&toolbar=0&page=' + page_no;
iframe.contentWindow.location.reload( true );
});
This works great in chrome, but firefox (v 23) gives me this error: "Permission denied to access property 'hash'".
Does anybody know why?
Thanks.
The ContainsText method finds the text only in specific area in the html but fails to find id in other parts of the page.
The text that located under 'div id="content"' can be found
But the text in other area of the html is not found (f.e 'form id="aspnetForm"')
Browser b = new FireFox("http://localhost:8668/login.aspx");
b.Button("login.login.button")).Click();
bool blah = b.ContainsText("Hello");
I'm using the latest watin release.
The issue is reproduced with FF3.0, FF3.5 and FF3.6
In IE it's working fine for the tested text.
Used workaround:
By parsing the html with html agility pack
Looks like this:
public bool ContainsTextInternal(string text)
{
var htmldoc = new HtmlDocument();
htmldoc.LoadHtml(browser.Html);
return htmldoc.DocumentNode.InnerText.Contains(text);
}
html agility pack link
I have protocol (like http) with scheme managed with 3rd party App registered in Mac OS X.
I.e, x-someapp://someaction or something like that.
How can I open this URL with Google Chrome?
By default, Chrome starts searching in Google engine instead launching App and passing URL handling to it...
Safari launches some registered App. And it is right thing.
Firefox and Opera asks what to do... and I can launch App also.
But Chrome... Doesn't ask.
I even tried to write some HTML page with JavaScript inside to send XHttpRequest:
function _httpExecuteCallback()
{
if (httpRequestCallbackFunction != null) {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
httpRequestCallbackFunction();
httpRequestCallbackFunction = null;
}
}
}
}
function _httpGet(url, callbackFunction)
{
httpRequest = false;
httpRequestCallbackFunction = callbackFunction;
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = _httpExecuteCallback;
httpRequest.open('GET', url, true);
httpRequest.send(null);
}
_httpGet('x-someapp://test',function(){})
No results also...
The current accepted solution has a problem with Chrome for SSL https. Watching the console log, Chrome blocks the request because it thinks the custom url protocol is not secure:
[blocked] The page at reports blah blah ran insecure content from customproto//blah blah
Here is a solution (this took me a few days to research):
<input type='button' value='Test Custom Url' onclick='exec()'>
<script>
function submitRequest(buttonId) {
var d = (window.parent)?window.parent.document:window.document
if (d.getElementById(buttonId) == null || d.getElementById(buttonId) == undefined) return;
if (d.getElementById(buttonId).dispatchEvent) {
var e = d.createEvent("MouseEvents");
e.initEvent("click", true, true);
d.getElementById(buttonId).dispatchEvent(e);
}
else {
d.getElementById(buttonId).click();
}
}
function exec(){
var d = (window.parent)?window.parent.document:window.document
var f = d.getElementById('customUrlLink')
if (f ) {f.parentNode.removeChild(f);}
var a = d.createElement('a');
a.href = 'mycustomproto://arg1';
a.innerHTML = "Link"
a.setAttribute('id', 'customUrlLink');
a.setAttribute("style", "display:none; ");
d.body.appendChild(a);
submitRequest("customUrlLink");
}
</script>
This code will not work for IE. I've found using this technique IE limits the argument of the custom protocol to less than 1000 where as using the iFrame technique IE will allow 2083 chars.
The only way to overcome the url limit in javascript is chuck the data and call multiple times. If anyone wants to take a stab at that, please let me know how it goes. I would like to use it.
To handle long urls in the executing app, pass a token into the app and have it go get the data from a url GET.
So for right now I am using one function for Chrome/FF and another function for IE.
These links helped me develop this solution:
https://superuser.com/questions/655405/custom-protocol-handler-not-working-in-chrome-on-ssl-page
Simulating a click in jQuery/JavaScript on a link
(wish I had known this a few days ago....hope this helps someone)
==================================================
Update: (8hr later)
==================================================
Jake posted a great solution for chrome: https://superuser.com/questions/655405/custom-protocol-handler-not-working-in-chrome-on-ssl-page
This works in chrome only:
window.location.assign("customprotocol://");
It will fail in an iframe so this is working:
var w = (window.parent)?window.parent:window
w.location.assign(service + '://' + data)
==================================================
Update: (weeks later)
==================================================
All of the examples of opening the custom protocol, including my own, have a "://" in the url. And this is what is causing the SSL warnings.
Turns out the solution is to change "://" to ":"
so do this:
src="x-myproto:query" .....
and the SSL warnings will go away.
==================================================
Follow: (after months of production use)
==================================================
This has been working well for chorme. Detect the browser and if chrome do this:
var w = (window.parent)?window.parent:window
w.location.assign('myproto://xyzabcdefetc')
For IE and other browsers I do something slightly different.
Note that browsers do impose a limit on how much data you can put in custom url protocol. As long as your string is under 800 chars this seems to be the magic number for which works in all browsers.
It looks like it's Google's locationbar parsing which is getting in the way.
The browser, however, does seem to handle custom URL schemes properly. Try this in your locationbar:
javascript:document.location = 'myscheme://whatever'
Any link on your page that uses the custom scheme should also do the right thing.
I found the solution that works with Chrome.
I use the IFRAME-way.
Example (with JQuery):
$("body").append('<span id="__protoProxy"></span>');
function queryWord(aWord)
{
var protoProxy = document.getElementById('__protoProxy');
if (protoProxy)
{
var word = aWord.replace('"','\"');
protoProxy.innerHTML = '<div style="display:none;"><iframe src="x-myproto://query?' + word + '"></iframe></div>';
}
}
queryWord('hello');
Here's a solution that also includes a redirect to the App Store / Play Store if the user doesn't have the app. It uses a setTimeout for this. It also makes use of an iframe to support more browsers. So this works on Chrome, and any other mobile browser. We use this as my company, Branch. Just modify the two links below to correspond to your URI and App Store link.
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
window.onload = function() {
// Deep link to your app goes here
document.getElementById("l").src = "my_app://somepath";
setTimeout(function() {
// Link to the App Store should go here -- only fires if deep link fails
window.location = "https://itunes.apple.com/us/app/myapp/id123456789?ls=1&mt=8";
}, 500);
};
</script>
<iframe id="l" width="1" height="1" style="visibility:hidden"></iframe>
</body>
</html>
Again, this should work on any browser, thanks to the iframe.
If Chrome does not recognize the URL scheme, it defaults to a search.
This is what I see in Safari:
alt text http://img62.imageshack.us/img62/6792/clipboard02oh.jpg
and in Firefox:
alt text http://img138.imageshack.us/img138/9986/clipboard04xk.jpg
I believe the reason why Chrome defaults to search is that there are special google searches that use the colon.
E.g:
define: dictionary
filetype:pdf google chromium
This is one of the annoyances I have with Firefox, I have to jump to the "search box" rather than the address bar to execute these types of searches. Since Chrome does not have a separate search box like Firefox, IE and Safari have, this functionality is required.
Ajax requests won't get you around this.
Some weeks later ....
Looks like window.location.replace('myscheme://whatever') has full cross-browser support , works with chrome,firefox,safari,edge,opera see https://developer.mozilla.org/en-US/docs/Web/API/Location/replace